/*******************************************************************************
 * Copyright(c) 2023 Levetop Semiconductor Co.,Led. All rights reserved.
 * @file     bsp.c
 * @author   UartTFT Application Team
 * @version  V0.0.1
 * @date     2023-01-11
 * @brief    This file provides UartTFT Application display function
 ********************************************************************************/

#include "bsp.h"
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "pit.h"
#include "bsp_user.h"
#include "tp_ctp.h"
#include "tp_rtp.h"
#include "iic.h"
#include "data.h"
#include "wav.h"
#include "levetop.h"
#include "function_drv.h"
#include "sincos_table.h"
#include "rtc.h"
#include "debug.h"
#include "eflash.h"
#include "tftlcd_spi.h"
#include "tftlcd_ebi_8bit.h"
#include "tftlcd_ebi_16bit.h"
#include "tftlcd_qspi.h"
#include "lt168.h"
#include "lt168_eport.h"
#include "lt168_pin.h"
#include "lt168_eic.h"
#include "lt168_clock.h"
#include "usb.h"
#include "communicate_Uart.h"
#include "communicate_Modbus.h"
#include "communicate_IIC.h"
#include "communicate_HID_CDC.h"

//zyy----------------------------
#include "gif.h"
#include "analogClock.h"
#include "digitalClock.h"
#include "scrollText.h"
#include "uiCounter.h"
#include "varCounter.h"
#include "needle.h"
#include "gesture.h"
#include "button.h"
#include "varButton.h"
#include "sliderBar.h"
#include "circularTouch.h"
#include "slideMenu.h"
#include "keyBoard.h"
#include "multiVarButton.h"
#include "uiCounter.h"
#include "popupBox.h"
#include "curve.h"
#include "uiQRCode.h"
#include "uiEncoder.h"
#include "uiIcon.h"
//--------------------------------

uint8_t page_refreshing = 0;

/*configuration parameter variable*/
uint8_t buzzer = 0;
uint16_t Start_page = 0;
uint8_t SCI_C0 = 0x5A;
uint8_t SCI_C1 = 0xA5;
uint8_t CRC_Enable_Flag = 1;
uint8_t CRC_Feedback_Flag = 1;

uint8_t TFT_bitcolor = 0;
uint8_t parity_flag = 0;
uint8_t multi_language = 0;
uint8_t multi_language_count = 0;

uint8_t UI_update = 0;
uint8_t lt_ui_change = 0;
uint8_t lt_screen_dir = 0;

/*ModBus operating variables*/
uint16_t Cnt_ModbusTX = 0; // record the offset position of Modbus operation parameters
uint16_t Sum_ModbusTX = 0; // total length of Modbus operation parameters

/*picture information*/
uint16_t pic_id = 0;
uint16_t pic_id_popup = 0;   //for pop-up
uint16_t pic_id_temp = 0;    //for keyboard
uint32_t pic_add = 0;
uint16_t pic_w = 0;
uint16_t pic_h = 0;
uint32_t pic_len = 0;
uint8_t pic_flag = 0;

/*backlight information*/
uint16_t gDutyBuf[64] = {0, 8, 16, 24, 32, 40, 48, 56, 64, 72, 80, 88, 96, 104, 112, 120, 128, 136, 144, 152, 160, 168, 176, 184, 192,
						 200, 208, 216, 224, 232, 240, 248, 256, 264, 272, 280, 288, 296, 304, 312, 320, 328, 336, 344, 352, 360, 368, 376, 384, 392,
						 400, 408, 416, 424, 432, 440, 448, 456, 464, 472, 480, 488, 496, 500};

uint8_t Auto_Backlight = 0;
uint32_t Backlight_count = 0;
uint8_t Backlight_flag = 0;
uint8_t Backlight_touch = 0;
uint8_t Backlight_time = 0;

/*Variable space*/
uint8_t var[VAR_SIZE+VAR_MODBUS_SIZE] = {0};		// variable buffer(reserved)
uint8_t var_temp[VAR_SIZE] = {0};				// variable buffer
uint8_t config_buff[PAGECFG_SIZE] = {0}; 
uint8_t config_buff_overlay[1024] = {0};		// variable buffer
uint8_t Display_buff[STRLEN_SIZE];				// display buffer
uint8_t Display_buff_temp[STRLEN_SIZE];			// display buffer

uint8_t g_upbuffer[1024*4];		// updata mcu buffer 4k
uint8_t g_upflag = 0;		    //

/*data display*/
uint8_t data_D_num = 0;					 // width used to recorddata display
uint16_t data_D_w[DATA_WLEN_SIZE] = {0}; // width used to recorddata display
uint16_t data_w = 0;

/*picture data display*/
uint8_t pdata_D_num;					   // width used to record picture data display
uint16_t pdata_D_w[PDATA_WLEN_SIZE] = {0}; // width used to record picture data display

/*touch public*/
uint8_t button_Press_flag = 0; // other touch cannot act after the touch is pressed
uint8_t buzzer_start = 0;
uint8_t buzzer_10ms_count = 0;
uint8_t Button_Key_Code_Flag = 0;
uint16_t Button_Key_Code = 0;

uint8_t Ascii_w[95] = {0};

const uint32_t CRC32_Table[256] = {
	0x00000000, 0x77073096, 0xEE0E612C, 0x990951BA, 0x076DC419,
	0x706AF48F, 0xE963A535, 0x9E6495A3, 0x0EDB8832, 0x79DCB8A4,
	0xE0D5E91E, 0x97D2D988, 0x09B64C2B, 0x7EB17CBD, 0xE7B82D07,
	0x90BF1D91, 0x1DB71064, 0x6AB020F2, 0xF3B97148, 0x84BE41DE,
	0x1ADAD47D, 0x6DDDE4EB, 0xF4D4B551, 0x83D385C7, 0x136C9856,
	0x646BA8C0, 0xFD62F97A, 0x8A65C9EC, 0x14015C4F, 0x63066CD9,
	0xFA0F3D63, 0x8D080DF5, 0x3B6E20C8, 0x4C69105E, 0xD56041E4,
	0xA2677172, 0x3C03E4D1, 0x4B04D447, 0xD20D85FD, 0xA50AB56B,
	0x35B5A8FA, 0x42B2986C, 0xDBBBC9D6, 0xACBCF940, 0x32D86CE3,
	0x45DF5C75, 0xDCD60DCF, 0xABD13D59, 0x26D930AC, 0x51DE003A,
	0xC8D75180, 0xBFD06116, 0x21B4F4B5, 0x56B3C423, 0xCFBA9599,
	0xB8BDA50F, 0x2802B89E, 0x5F058808, 0xC60CD9B2, 0xB10BE924,
	0x2F6F7C87, 0x58684C11, 0xC1611DAB, 0xB6662D3D, 0x76DC4190,
	0x01DB7106, 0x98D220BC, 0xEFD5102A, 0x71B18589, 0x06B6B51F,
	0x9FBFE4A5, 0xE8B8D433, 0x7807C9A2, 0x0F00F934, 0x9609A88E,
	0xE10E9818, 0x7F6A0DBB, 0x086D3D2D, 0x91646C97, 0xE6635C01,
	0x6B6B51F4, 0x1C6C6162, 0x856530D8, 0xF262004E, 0x6C0695ED,
	0x1B01A57B, 0x8208F4C1, 0xF50FC457, 0x65B0D9C6, 0x12B7E950,
	0x8BBEB8EA, 0xFCB9887C, 0x62DD1DDF, 0x15DA2D49, 0x8CD37CF3,
	0xFBD44C65, 0x4DB26158, 0x3AB551CE, 0xA3BC0074, 0xD4BB30E2,
	0x4ADFA541, 0x3DD895D7, 0xA4D1C46D, 0xD3D6F4FB, 0x4369E96A,
	0x346ED9FC, 0xAD678846, 0xDA60B8D0, 0x44042D73, 0x33031DE5,
	0xAA0A4C5F, 0xDD0D7CC9, 0x5005713C, 0x270241AA, 0xBE0B1010,
	0xC90C2086, 0x5768B525, 0x206F85B3, 0xB966D409, 0xCE61E49F,
	0x5EDEF90E, 0x29D9C998, 0xB0D09822, 0xC7D7A8B4, 0x59B33D17,
	0x2EB40D81, 0xB7BD5C3B, 0xC0BA6CAD, 0xEDB88320, 0x9ABFB3B6,
	0x03B6E20C, 0x74B1D29A, 0xEAD54739, 0x9DD277AF, 0x04DB2615,
	0x73DC1683, 0xE3630B12, 0x94643B84, 0x0D6D6A3E, 0x7A6A5AA8,
	0xE40ECF0B, 0x9309FF9D, 0x0A00AE27, 0x7D079EB1, 0xF00F9344,
	0x8708A3D2, 0x1E01F268, 0x6906C2FE, 0xF762575D, 0x806567CB,
	0x196C3671, 0x6E6B06E7, 0xFED41B76, 0x89D32BE0, 0x10DA7A5A,
	0x67DD4ACC, 0xF9B9DF6F, 0x8EBEEFF9, 0x17B7BE43, 0x60B08ED5,
	0xD6D6A3E8, 0xA1D1937E, 0x38D8C2C4, 0x4FDFF252, 0xD1BB67F1,
	0xA6BC5767, 0x3FB506DD, 0x48B2364B, 0xD80D2BDA, 0xAF0A1B4C,
	0x36034AF6, 0x41047A60, 0xDF60EFC3, 0xA867DF55, 0x316E8EEF,
	0x4669BE79, 0xCB61B38C, 0xBC66831A, 0x256FD2A0, 0x5268E236,
	0xCC0C7795, 0xBB0B4703, 0x220216B9, 0x5505262F, 0xC5BA3BBE,
	0xB2BD0B28, 0x2BB45A92, 0x5CB36A04, 0xC2D7FFA7, 0xB5D0CF31,
	0x2CD99E8B, 0x5BDEAE1D, 0x9B64C2B0, 0xEC63F226, 0x756AA39C,
	0x026D930A, 0x9C0906A9, 0xEB0E363F, 0x72076785, 0x05005713,
	0x95BF4A82, 0xE2B87A14, 0x7BB12BAE, 0x0CB61B38, 0x92D28E9B,
	0xE5D5BE0D, 0x7CDCEFB7, 0x0BDBDF21, 0x86D3D2D4, 0xF1D4E242,
	0x68DDB3F8, 0x1FDA836E, 0x81BE16CD, 0xF6B9265B, 0x6FB077E1,
	0x18B74777, 0x88085AE6, 0xFF0F6A70, 0x66063BCA, 0x11010B5C,
	0x8F659EFF, 0xF862AE69, 0x616BFFD3, 0x166CCF45, 0xA00AE278,
	0xD70DD2EE, 0x4E048354, 0x3903B3C2, 0xA7672661, 0xD06016F7,
	0x4969474D, 0x3E6E77DB, 0xAED16A4A, 0xD9D65ADC, 0x40DF0B66,
	0x37D83BF0, 0xA9BCAE53, 0xDEBB9EC5, 0x47B2CF7F, 0x30B5FFE9,
	0xBDBDF21C, 0xCABAC28A, 0x53B39330, 0x24B4A3A6, 0xBAD03605,
	0xCDD70693, 0x54DE5729, 0x23D967BF, 0xB3667A2E, 0xC4614AB8,
	0x5D681B02, 0x2A6F2B94, 0xB40BBE37, 0xC30C8EA1, 0x5A05DF1B,
	0x2D02EF8D};
/********************************************************************************
 * GetCrc32
 *********************************************************************************/
uint32_t GetCrc32(uint8_t *InStr,uint32_t len,uint32_t value)
{
    uint32_t i;
    uint32_t Crc;

    Crc=value;

    for(i=0; i<len; i++)
    {
        Crc = (Crc >> 8) ^ CRC32_Table[(Crc&0xFF)^(InStr[i])];
    }

    return Crc;
}

int Check_UIHead(void)
{
	uint32_t eflash_addr = 0;
	uint8_t rebuf[16] = {0};

	eflash_addr = 0x6007C000;
	EFlash_Read(eflash_addr,&rebuf[0],16);
	//LTPrintf("Check_UIHead %#X %#X %#X %#X %#X \r\n",rebuf[0],rebuf[1],rebuf[2],rebuf[3],rebuf[4],rebuf[5]);

	if(rebuf[0]==0xB8
		&&rebuf[1]==0xB1
		&&rebuf[2]==0xC6
		&&rebuf[3]==0xC1)
	{
		if(rebuf[4] == 0x6F && rebuf[5] == 0x6B)
			return 1;
	}

	//LTPrintf("Check_UIHead error \r\n");
	return 0;
}

void LT_check_UI_CRC(void)
{
#if Secondary_screen

	USB_HID_Init();

	if(!Check_UIHead())
	{
		LCD_XSIZE_TFT = 480;
		LCD_YSIZE_TFT = 320;
//		Screen_DIR = 0;
		SCI_C0 = 0x5A; // 帧头
		SCI_C1 = 0xA5;
		CRC_Enable_Flag   = 1; // CRC校准使能
		CRC_Feedback_Flag = 1; // 串口反馈使能

		UI_update = 2;

		LT268_TFT_FillColor(0,0,LCD_XSIZE_TFT-1,LCD_YSIZE_TFT-1,Blue2);
		LT268_TFT_ShowAscll(0, 10, 24, 0, Red, White, (uint8_t *)"Update Flash");
		LCD_BL_Init(gDutyBuf[40]); /* backlight */

		while(1)
		{
			Hid_Main_From_UartRxBuff();
			if(gHidRx.Flag)  LT_Hid_ReceiveCmd(gHidRx.Buf);
			if(UI_update == 0)
			{
				if(!Check_UIHead())
				{
					UI_update = 2;
					LT268_TFT_FillColor(0,0,LCD_XSIZE_TFT-1,LCD_YSIZE_TFT-1,Blue2);
					LT268_TFT_ShowAscll(0, 10, 24, 0, Red, White, (uint8_t *)"Update Flash error");
				}
				else
					break;
			}
		}
	}
	 /* get ui info */
	LT_ReadParam();
#endif
}

//--------------------------------------------------------------------------------------
typedef void (*iapfun)(void); // Define parameters of a function type.

iapfun jump2app;

#define APP_ADDR          0x6000A000	//MCU Code run at 0x6000A000(0x60000000+1024*40)
#define UPDATE_KEY_ADDR   0x6007E000	//Update key，goto bootloader from mcu code，index(0x21436587)at 0x6007E000
#define Run_Boot_ID	   (*(volatile uint32_t *)(0x00800800-4))//Update key，goto bootloader from mcu code，index(0x47210659)at 0x6007E000

void APP(uint32_t appxaddr)
{
	uint32_t enterAddr;
	uint32_t tCRC = 0xFFFFFFFF;

	EFlash_Init();
	EFLASH_Write(UPDATE_KEY_ADDR,(uint8_t *)&tCRC,4);

	LT_BacklightClose();

	EIC->IER = 0;								//Disable All Interrupts
	WDT->WCR = 0x0;

	enterAddr = IO_READ32(appxaddr);
	((void (*)(void))((unsigned int*)enterAddr))();

	while(1);
}
//--------------------------------------------------------------------------------------

void Var_AddrRemapping(uint16_t *addr)     // reg address mapping to var array
{
	if (*addr >= VAR_REG_S && *addr <= VAR_REG_E) 
		*addr -= (VAR_REG_S-VAR_ADDR_S);

//	if (*addr > (VAR_ADDR_E + 0xFF))
//		*addr = 0;
//	;
}

void Var_AddrToReg(uint8_t *buf)         // var array mapping to reg address
{
	uint16_t addr = (buf[0]<<8)|(buf[1]);

	if((addr >= VAR_ADDR_S && addr <= VAR_ADDR_E)) 
	{
		addr += (VAR_REG_S-VAR_ADDR_S);
		buf[0] = (addr>>8)&0xFF;
		buf[1] = addr&0xFF;
	}
}

/********************************************************************************
 * Function Name : reg_operation
 * Description   : Operation register.
 * Input         : - addr: register address
 * Output        : None
 * Return        : None
 *********************************************************************************/
void reg_operation(uint16_t addr)
{
	if (addr == VAR_PAGE)
	{
		if (pic_id != (var[VAR_PAGE * 2] << 8) + var[VAR_PAGE * 2 + 1])
		{
			Display_page((var[VAR_PAGE * 2] << 8) + var[VAR_PAGE * 2 + 1]);
		}
	}
	else if (addr == VAR_BL)
	{
		if (var[VAR_BL * 2 + 1] > 63)
			var[VAR_BL * 2 + 1] = 63;

		LT_BacklightSet(gDutyBuf[var[VAR_BL * 2 + 1]]);
		Backlight_flag = 1;
//		if (Auto_Backlight)
//		{
//			Backlight_count = 0;
//			Backlight_flag = 1;
//		}
	}
	else if (addr == VAR_TIMESET) // time setting
	{
		RTC_Get();

		if (var[VAR_TIMESET * 2 + 1] == 0)
		{

		}
		else if (var[VAR_TIMESET * 2 + 1] == 1)
		{
			var[(VAR_TIME + 3) * 2 + 1] = calendar.hour;
			var[(VAR_TIME + 4) * 2 + 1] = calendar.min;
			var[(VAR_TIME + 5) * 2 + 1] = calendar.sec;
		}
		else if (var[VAR_TIMESET * 2 + 1] == 2)
		{
			var[(VAR_TIME + 2) * 2 + 1] = calendar.w_date;
			var[(VAR_TIME + 3) * 2 + 1] = calendar.hour;
			var[(VAR_TIME + 4) * 2 + 1] = calendar.min;
			var[(VAR_TIME + 5) * 2 + 1] = calendar.sec;
		}
		else if (var[VAR_TIMESET * 2 + 1] == 3)
		{
			var[(VAR_TIME + 0) * 2 + 1] = calendar.w_year - 2000;
			var[(VAR_TIME + 3) * 2 + 1] = calendar.hour;
			var[(VAR_TIME + 4) * 2 + 1] = calendar.min;
			var[(VAR_TIME + 5) * 2 + 1] = calendar.sec;
		}
		else if (var[VAR_TIMESET * 2 + 1] == 4)
		{
			var[(VAR_TIME + 0) * 2 + 1] = calendar.w_year - 2000;
			var[(VAR_TIME + 1) * 2 + 1] = calendar.w_month;
			var[(VAR_TIME + 2) * 2 + 1] = calendar.w_date;
		}
		else if (var[VAR_TIMESET * 2 + 1] == 5)
		{
			var[(VAR_TIME + 0) * 2 + 1] = calendar.w_year - 2000;
			var[(VAR_TIME + 1) * 2 + 1] = calendar.w_month;
			var[(VAR_TIME + 2) * 2 + 1] = calendar.w_date;
			var[(VAR_TIME + 5) * 2 + 1] = calendar.sec;
		}
		else if (var[VAR_TIMESET * 2 + 1] == 6)
		{
			var[(VAR_TIME + 0) * 2 + 1] = calendar.w_year - 2000;
			var[(VAR_TIME + 1) * 2 + 1] = calendar.w_month;
			var[(VAR_TIME + 2) * 2 + 1] = calendar.w_date;
			var[(VAR_TIME + 3) * 2 + 1] = calendar.hour;
		}
		RTC_Set(2000 + var[(VAR_TIME + 0) * 2 + 1], var[(VAR_TIME + 1) * 2 + 1], var[(VAR_TIME + 2) * 2 + 1], var[(VAR_TIME + 3) * 2 + 1], var[(VAR_TIME + 4) * 2 + 1], var[(VAR_TIME + 5) * 2 + 1]);
	}
	else if (addr == VAR_WAV)
	{
		Wav_DAC_Init((var[VAR_WAV * 2] << 8) + var[VAR_WAV * 2 + 1]);
	}
	else if (addr == VAR_VOLUME)
	{
		if (var[2 * VAR_VOLUME + 1] > 16)
			wav_reduce_para = 16;
		else
			wav_reduce_para = var[2 * VAR_VOLUME + 1];
	}
	else if (addr == VAR_KEY)
	{
		Button_Key_Code = (var[VAR_KEY * 2] << 8) | var[VAR_KEY * 2 + 1];
		Button_Key_Code_Flag = 1;
	}
	else if (addr == VAR_BLAUTO)
	{
		if(var[2 * VAR_BLAUTO + 1] == 1)
		{
			if (Backlight_flag == 0)
			{	
				Backlight_count = 0;								
				Backlight_flag = 1;
				LT_BacklightSet(gDutyBuf[var[VAR_BL * 2 + 1]]);
			}
		}
		else if (var[2 * VAR_BLAUTO + 1] == 0)
		{
			Backlight_count = 0;								
			Backlight_flag = 0;
			LT_BacklightSet(gDutyBuf[var[VAR_BL * 2 + 1]]);
		}
	}
	else if (addr == VAR_BLSLEEP)
	{
		if (Backlight_flag == 0 && var[2 * VAR_BLAUTO + 1] == 1)
		{
			LT_BacklightSet(gDutyBuf[var[VAR_BLSLEEP * 2 + 1]]);
		}
	}
	else if (addr == VAR_MCURESET)
	{
		if (var[2 * VAR_MCURESET] == 0xAA && var[2 * VAR_MCURESET + 1] == 0x55)
		{
			var[2 * VAR_MCURESET] = 0;
			var[2 * VAR_MCURESET + 1] = 0;

			APP(0x60000000);
		}
	}
	else if (addr == VAR_MTLANGUAGE)
	{
		if (var[2 * VAR_MTLANGUAGE + 1] < multi_language_count && var[2 * VAR_MTLANGUAGE + 1] != multi_language)
		{
			uint8_t language_buff[2048];
			uint32_t language_sum = 0,language_count = 0,L_count = 0;
			uint32_t language_addr = 0,L_addr,L_len = 0;
			uint16_t L_num;
			multi_language = var[2 * VAR_MTLANGUAGE + 1];
			
			if (addr_index[19] > 0)
			{
				LT_ReadFlash_UI(language_buff, addr_index[18] + 8 * multi_language, 8);
				language_addr = (language_buff[0]) + (language_buff[1] << 8) + (language_buff[2] << 16) + (language_buff[3] << 24);
				language_sum = (language_buff[4]) + (language_buff[5] << 8) + (language_buff[6] << 16) + (language_buff[7] << 24);
			}
			if (language_sum > 0)
			{
				if (language_sum - language_count >=2048)
						LT_ReadFlash_UI(language_buff,language_addr,2048);
				else 
					LT_ReadFlash_UI(language_buff,language_addr,language_sum);
				
				while(1)
				{
					if (L_count + 4 > 2048)
					{
						if (language_sum - language_count >= 2048)
							LT_ReadFlash_UI(language_buff,language_addr + language_count,2048);
						else 
							LT_ReadFlash_UI(language_buff,language_addr + language_count,language_sum - language_count);
						L_count = 0;
					}
					L_addr = language_buff[L_count] + (language_buff[L_count + 1] << 8);
					L_len = language_buff[L_count + 2] + (language_buff[L_count + 3] << 8);
					L_count = L_count + 4;
					
					if(L_count + L_len > 2048)
					{
						if (language_sum - (language_count + 4) >= 2048)
							LT_ReadFlash_UI(language_buff,language_addr + language_count + 4,2048);
						else 
							LT_ReadFlash_UI(language_buff,language_addr + language_count + 4 ,language_sum - (language_count + 4));
						L_count = 0;
					}
					
					for (uint16_t ll = 0; ll < L_len; ll++)
					{
						var[L_addr * 2 + ll] = language_buff[L_count + ll];
					}
					language_count += L_len + 4;
					L_count += L_len;
					
					if(language_count >= language_sum)
						break;
				}
			}

			if(Pop_up_flag == 1)
			{
				Display_pop_up(Pop_up_id,Pop_up_x,Pop_up_y);
			}
			else Display_page(pic_id);
		}
		else
			var[2 * VAR_MTLANGUAGE + 1] = multi_language;
	}
	else if (addr == VAR_UI_CHANGE)
	{
		if(lt_ui_change != var[VAR_UI_CHANGE * 2 + 1])
			LT_LCD_screen_dir(var[VAR_UI_CHANGE * 2 + 1]);
	}
	else if (addr == VAR_ENCODE)
	{
		
	}
	else if (addr == VAR_MCU_LPOWER)
	{
		lt_mcu_low_power();
	}
}

void lt_page_widget_count_delete(uint8_t mode)
{
	if(mode == 0)   // new page
	{
        //0x0001
		//0x0002
		data_D_num = 0;
		memset(data_D_w, 0, sizeof(data_D_w));
		//0x0003
		//0x0004
		pdata_D_num = 0;
		memset(pdata_D_w, 0, sizeof(pdata_D_w));
		//0x0005
		Gif_num = 0;
		//0x0006
		RTC_num = 0;
		//0x0007
		//0x0008
		Clock_num = 0;
		//0x0009
		Scroll_num = 0;
		//0x000A
		if (gWav_status>0)
		{
			gWavType = 0;
			gWav_status = 1;
			// close_wav_dac();
		}

		//0x000B
		//0x000C
		//0x000D
		curve_num = 0;
		//0x000E
		gEncoderFlag = 0;
		knob_flag = 0;
		var[VAR_ENCODE * 2 + 1] = 0;
		//0x000F
		//0x0010
		Count_sum = 0;
		Saving_counting_parameters(); // Save data for time counter
		//0x0011
		Var_Count_num = 0;
		//0x0012
		Pointer_Count_num = 0;
		Pointer_Count_flag = 0;

		//0x8000
		Gesture_flag = 0;
		Gesture_press = 0;
		//0x8001
		Basci_count = 0;
		Basci_flag = 0;
		button_Press_flag = 0;
		//0x8002
		Dio_count = 0;
		Dio_flag = 0;
		DioKb_flag = 0;
		//0x8003
		Adj_count = 0;
		Adj_flag = 0;
		//0x8004
		Slide_count = 0;
		Slide_flag = 0;
		//0x8005
		Kb_count = 0;
		Kb_flag = 0;
		//0x8006
		sldmenu_count = 0;
		sldmenu_flag = 0;
		//0x8007
		RingSld_count = 0;
		//0x8008
		Pop_up_count = 0;
		Pop_up_flag = 0;
		//0x8009
		Aio_count = 0;
		AioKb_flag = 0;
		Aio_flag = 0;
		//0x800A
		GBKio_count = 0;
		GBKioKb_flag = 0;
		GBKio_flag = 0;
		//0x800B
		VarKey_count = 0;
		VarKey_flag = 0;
		//0x800C
//		Ges_sc_flag = 0;

		// register addr
		// key function
//		Button_Key_Code_Flag = 0;
//		Button_Key_Code = 0;

#if (UARTBUS_OPTION == 2)
		if (gUsartTx.Mode == 0x02)
			tx_repeat_flag = 0;
#endif

		RTC_Get();
		var[(VAR_TIME + 0) * 2 + 1] = calendar.w_year - 2000;
		var[(VAR_TIME + 1) * 2 + 1] = calendar.w_month;
		var[(VAR_TIME + 2) * 2 + 1] = calendar.w_date;
		var[(VAR_TIME + 3) * 2 + 1] = calendar.hour;
		var[(VAR_TIME + 4) * 2 + 1] = calendar.min;
		var[(VAR_TIME + 5) * 2 + 1] = calendar.sec;
		var[VAR_TIMESET * 2 + 1] = calendar.week;
	}
	else if(mode == 1) // new popup page
	{
        //0x0001
		//0x0002
		data_D_num = 0;
		memset(data_D_w, 0, sizeof(data_D_w));
		//0x0003
		//0x0004
		pdata_D_num = 0;
		memset(pdata_D_w, 0, sizeof(pdata_D_w));
		//0x0005
		Gif_num = 0;
		//0x0006
		RTC_num = 0;
		//0x0007
		//0x0008
		Clock_num = 0;
		//0x0009
		Scroll_num = 0;
		//0x000A
			// gWavType = 0;
			// close_wav_dac();
		//0x000B
		//0x000C
		//0x000D
		curve_num = 0;
		//0x000E
		gEncoderFlag = 0;
		knob_flag = 0;
		var[VAR_ENCODE * 2 + 1] = 0;
		//0x000F
		//0x0010
		Count_sum = 0;
		Saving_counting_parameters(); // Save data for time counter
		//0x0011
		Var_Count_num = 0;
		//0x0012
		Pointer_Count_num = 0;
		Pointer_Count_flag = 0;

		//0x8000
		Gesture_flag = 0;
		Gesture_press = 0;
		//0x8001
		Basci_count = 0;
		Basci_flag = 0;
		button_Press_flag = 0;
		//0x8002
		Dio_count = 0;
		Dio_flag = 0;
		DioKb_flag = 0;
		//0x8003
		Adj_count = 0;
		Adj_flag = 0;
		//0x8004
		Slide_count = 0;
		Slide_flag = 0;
		//0x8005
		Kb_count = 0;
		Kb_flag = 0;
		//0x8006
		sldmenu_count = 0;
		sldmenu_flag = 0;
		//0x8007
		RingSld_count = 0;
		//0x8008
		Pop_up_count = 0;
		Pop_up_flag = 1;
		//0x8009
		Aio_count = 0;
		AioKb_flag = 0;
		Aio_flag = 0;
		//0x800A
		GBKio_count = 0;
		GBKioKb_flag = 0;
		GBKio_flag = 0;
		//0x800B
		VarKey_count = 0;
		VarKey_flag = 0;
		//0x800C
//		Ges_sc_flag = 0;

		// register addr
		// key function
//		Button_Key_Code_Flag = 0;
//		Button_Key_Code = 0;

#if (UARTBUS_OPTION == 2)
		if (gUsartTx.Mode == 0x02)
			tx_repeat_flag = 0;
#endif

		RTC_Get();
		var[(VAR_TIME + 0) * 2 + 1] = calendar.w_year - 2000;
		var[(VAR_TIME + 1) * 2 + 1] = calendar.w_month;
		var[(VAR_TIME + 2) * 2 + 1] = calendar.w_date;
		var[(VAR_TIME + 3) * 2 + 1] = calendar.hour;
		var[(VAR_TIME + 4) * 2 + 1] = calendar.min;
		var[(VAR_TIME + 5) * 2 + 1] = calendar.sec;
		var[VAR_TIMESET * 2 + 1] = calendar.week;
	}
}

/***********************************************************************************
 * Function Name : Display_page
 * Description   : Display the interface of a page.
 * Input         : - id: Page No
 * Output        : None
 * Return        : None
 ************************************************************************************/
void Display_page(uint16_t id)
{
	if (id < addr_index[7])
	{
		uint8_t buff[12] = {0};

		var[VAR_PAGE * 2 + 0] = id >> 8;
		var[VAR_PAGE * 2 + 1] = id & 0xFF;

		LT_ReadFlash_UI(buff, addr_index[6] + 12 * id, 12);
		pic_add = (buff[0]) + (buff[1] << 8) + (buff[2] << 16) + (buff[3] << 24);
		pic_w = buff[4] + (buff[5] << 8);
		pic_h = buff[6] + (buff[7] << 8);
		pic_len = buff[8] + (buff[9] << 8) + (buff[10] << 16);
		pic_flag = buff[11];
		pic_id = id;

		FullScreen_addr = pic_add;
		FullScreen_W = pic_w;
		FullScreen_H = pic_h;
		FullScreen_color = pic_len;
		FullScreen_flag = pic_flag;  //set 0
//		LCD_XSIZE_TFT = pic_w;
//		LCD_YSIZE_TFT = pic_h;

		lt_page_widget_count_delete(0);
		
#if LT_PAGE_FULLBUFF
		diplay_info.to_flag = PIC_TO_FULLBUFF;
		diplay_info.p = dispaly_ram;
		// debug
		// LTPrintf("page id: %d , page info: %d  %d  %d   %d  0x%x     \r\n",id,pic_w,pic_h,pic_len,pic_flag,pic_add);
		if (FullScreen_flag == ColorRGB565_zip)
		{
			// 将完整的zip底图放到dispaly_ram
			LT268_pic_to_buffer(0, 0, LCD_XSIZE_TFT, diplay_info.p,
								0, 0, FullScreen_W, FullScreen_addr,
								FullScreen_W, FullScreen_H, FullScreen_flag);
		}
		else if (FullScreen_flag == ColorPure)
			LT_ShowPicture(0, 0, FullScreen_W, FullScreen_H, FullScreen_addr, FullScreen_color, FullScreen_flag);
		else if (FullScreen_color != 0 && FullScreen_flag != 0xFF)
		{
			if (FullScreen_flag == ColorPure || FullScreen_flag == ColorRGB565)
				LT_ShowPicture(0, 0, FullScreen_W, FullScreen_H, FullScreen_addr, FullScreen_color, FullScreen_flag);
		}

		Get_date_variable_Id(id);
		Get_Touch_info(id);

		diplay_info.to_flag = PIC_TO_SCREEN;

		// display (TE)
		lt_screen_frame_update();

		if (FullScreen_flag == ColorRGB565_zip) // 压缩底图备份
		{
			// 将完整的zip底图放到dispaly_ram
			LT268_pic_to_buffer(0, 0, LCD_XSIZE_TFT, diplay_info.p,
								0, 0, FullScreen_W, FullScreen_addr,
								FullScreen_W, FullScreen_H, FullScreen_flag);
		}
#else

		// debug
		// LTPrintf("page id: %d , page info: %d  %d  %d   %d  0x%x     \r\n",id,pic_w,pic_h,pic_len,pic_flag,pic_add);
		if (pic_flag == ColorRGB565_zip)
		{
			// 将完整的zip底图放到dispaly_ram
			LT268_pic_to_buffer(0, 0, LCD_XSIZE_TFT, dispaly_ram,
								0, 0, FullScreen_W, FullScreen_addr,
								FullScreen_W, FullScreen_H, FullScreen_flag);
			LT268_buffer_to_TFT(0, 0, LCD_XSIZE_TFT, dispaly_ram,
								0, 0, FullScreen_W, FullScreen_H);
#if (LT_TFT_PORT == 0 || LT_TFT_PORT == 1 || LT_TFT_PORT == 3) // for byteswap
			LT268_pic_to_buffer(0, 0, LCD_XSIZE_TFT, dispaly_ram,
								0, 0, FullScreen_W, FullScreen_addr,
								FullScreen_W, FullScreen_H, FullScreen_flag);
#endif
		}
		else if (pic_flag == ColorPure)
			LT_ShowPicture(0, 0, pic_w, pic_h, pic_add, pic_len, pic_flag);
		else if (pic_len != 0 && pic_flag != 0xFF)
		{
			if (pic_flag == ColorPure || pic_flag == ColorRGB565)
				LT_ShowPicture(0, 0, pic_w, pic_h, pic_add, pic_len, pic_flag);
		}
		Get_date_variable_Id(id);
		Get_Touch_info(id);
#endif
	}
}

/***********************************************************************************
* Function Name : Display_pop_up
* Description   : Show pop-up page.
* Input         : - id: page id
				  - x,y: Screen coordinates
* Output        : None
* Return        : None
************************************************************************************/
void Display_pop_up(uint16_t id, uint16_t x, uint16_t y)
{
	if (id < addr_index[7])
	{
		uint8_t buff[12] = {0};
		uint16_t w, h;
		uint8_t bgflag = 0;

		LT_ReadFlash_UI(buff, addr_index[6] + 12 * id, 12);
		pic_add = (buff[0]) + (buff[1] << 8) + (buff[2] << 16) + (buff[3] << 24);
		pic_w = buff[4] + (buff[5] << 8);
		pic_h = buff[6] + (buff[7] << 8);
		pic_len = buff[8] + (buff[9] << 8) + (buff[10] << 16);
		pic_flag = buff[11];
		pic_id = id;
		w = pic_w;
		h = pic_h;

		// var[VAR_PAGE * 2 + 0] = pic_id >> 8;
		// var[VAR_PAGE * 2 + 1] = pic_id & 0xFF;

		// debug
//		 LTPrintf("Display_pop_up: %d , page info: %d  %d  %d   %d  0x%x     \r\n",id,pic_w,pic_h,pic_len,pic_flag,pic_add);

		Page_VirAddr = pic_add;
		Page_VirLen = pic_len;
		Page_VirFlag = pic_flag;   // set 0 
		Page_VirW = pic_w;
		Page_VirH = pic_h;

		lt_page_widget_count_delete(1);

		if ((gPop_up_Info[Pop_up_num].function & 0x01) == 1) // bokeh background
		{
			bgflag = 1;
		}

		if (pic_flag == ColorPure)
		{
			LT_ShowPicture(x, y, pic_w, pic_h, pic_add, pic_len, pic_flag);
		}
		else if(pic_len != 0 && pic_flag != 0xFF)
		{
			if(pic_flag == ColorRGB565_zip || pic_flag == ColorARGB0565_zip || pic_flag == ColorARGB4444_zip)
			{
				//将完整的zip底图放到dispaly_ram
				LT268_pic_to_buffer(0,0,LCD_XSIZE_TFT,dispaly_ram,
						0,0,FullScreen_W,FullScreen_addr,
						FullScreen_W,FullScreen_H,FullScreen_flag);
				//将完整的zip弹窗放到dispaly_ram
				LT268_pic_to_buffer(x,y,LCD_XSIZE_TFT,dispaly_ram,
						0,0,pic_w,pic_add,
						pic_w,pic_h,pic_flag);
				LT268_buffer_to_TFT(x,y,LCD_XSIZE_TFT,dispaly_ram,
					x,y,pic_w,pic_h);
			}
			else if (pic_flag == ColorPure || pic_flag == ColorRGB565)
			{
				LT_ShowPicture(x, y, pic_w, pic_h, pic_add, pic_len, pic_flag);
			}
			else if (pic_flag == ColorARGB0565 || pic_flag == ColorARGB4444)
			{
				//底图
				LT268_pic_to_buffer(0,0,pic_w,m_PngData,
						x,y,FullScreen_W,FullScreen_addr,
						pic_w,pic_h,FullScreen_flag);
				LT268_pic_to_buffer(0,0,pic_w,m_PngData,
						0,0,pic_w,pic_add,
						pic_w,pic_h,pic_flag);
				LT268_buffer_to_TFT(0,0,pic_w,m_PngData,
					x,y,pic_w,pic_h);
			}
		}
		Get_date_variable_Id(id);
		Get_Touch_info(id);
		Wav_DAC_Init((var[VAR_WAV * 2] << 8) + var[VAR_WAV * 2 + 1]);
	}
}

/*******************************************************************************
 * Function Name : LT_Print_zk_Font
 * Description   : Display a string.
 * Input         :
 * Output        : None
 * Return        : None
 ********************************************************************/
uint16_t LT_Print_zk_Font(
	uint16_t encode // encoding type, 0:GB2312  1:GBK  2:BIG5  3:UNICODE  4:ASCII
	,
	uint32_t FlashAddr // Font source address(exSpiFlash)
	,
	uint32_t ShowAddr // Displays the address of the layer
	,
	uint16_t width // Display the width of the layer
	,
	uint8_t W_Size // font width
	,
	uint8_t H_Size // font height
	,
	uint8_t Alignment // Alignment
	,
	uint32_t FontColor // The foreground color of the font
	,
	uint32_t BackColor // The background color of the font
	,
	uint8_t enbackcolor // Background color enable, 0:disable  1:enable
	,
	uint8_t mix // mix mode, 0:with fullscreen interface   1:with specific pictures(Text box needs to be fully included)
	,
	_PICINFO mixpic // mix picture info
	,
	uint8_t text_mode // text display mode: 0:txt  1:encryption use '*' (0x2A)
	,
	uint16_t Xs // Text box start x position
	,
	uint16_t Ys // Text box start Y position
	,
	uint16_t Xe // Text box end x position
	,
	uint16_t Ye // Text box end y position
	,
	uint8_t dis_x // The interval between two adjacent fonts on the x-axis
	,
	uint8_t dis_y // The interval between two adjacent fonts on the y-axis
	,
	uint8_t *c // Address of text
	,
	uint16_t len_max // max lenght of text
)
{
	uint32_t i = 0, j = 0;
	uint16_t X_start = 0, Y_start = 0;
	uint16_t box_w = Xe - Xs + 1, box_h = Ye - Ys + 1;
	uint8_t gray, gray_bit;
	uint16_t row = 0, row_num = 0, row_w[100]; // max line = 100
	uint16_t disp_w = 0, disp_i = 0,temp_w;
	uint8_t unicode_w;
	uint16_t font_byte; // bytes of a single font
//	uint16_t dis_w;
	uint16_t len_disp = 0, offset_disp = 0, W_Len = 0, H_Len = 0;
	uint16_t x_src = 0, y_src = 0, x_des = 0, y_des = 0, w_real = 0, h_real = 0;
	uint16_t scode,ecode;

	uint16_t unicode = 0, unicode_temp = 0;
	uint16_t start_code = 0, end_code = 0;
	uint8_t buff_code[4];
	uint16_t str_num = 0,k ;

	LT_ReadFlash_UI(Ascii_w, FlashAddr + 9, 95);
	LT_ReadFlash_UI(&gray, FlashAddr + 8, 1);

	if (gray == 0)
		gray_bit = 1;
	else if (gray == 1)
		gray_bit = 2;
	else if (gray == 2)
		gray_bit = 4;

	if (Screen_DIR == 0 || Screen_DIR == 2)
	{
		W_Len = Xe - Xs + 1;
		H_Len = Ye - Ys + 1;
	}
	else if (Screen_DIR == 1 || Screen_DIR == 3)
	{
		W_Len = Ye - Ys + 1;
		H_Len = Xe - Xs + 1;
	}

	if (encode == 4 || encode == 0 || encode == 1 || encode == 2) // ASCII GB2312 GBK BIG5
	{
		while (1) // Automatic exit when meeting the end-of-transmission
		{
			if (encode == 4)
			{
				if (c[i] < 128 && c[i] > 0x00)
					temp_w = (Ascii_w[c[i] - 0x20] + dis_x + 2);
				else if (c[i] == 0x0A)
					temp_w = 0; // newline
				else
					len_max = i; // coding error or max len (Exit after entering the display)
			}
			else if (encode == 0)
			{
				if (c[i] < 128 && c[i] > 0x00)
				temp_w = Ascii_w[c[i] - 0x20] + dis_x + 2;
				else if (c[i] >= 0xa1 && c[i] != 0xFF)
					temp_w = W_Size + dis_x;
				else if (c[i] == 0x0A)
					temp_w = 0; // newline
				else
					len_max = i; // coding error or max len (Exit after entering the display)
			}
			else if (encode == 1)
			{
				if (c[i] < 128 && c[i] > 0x00)
					temp_w = Ascii_w[c[i] - 0x20] + dis_x + 2;
				else if (c[i] >= 0x81 && c[i + 1] >= 0x40 && c[i] != 0xFF)
					temp_w = W_Size + dis_x;
				else if (c[i] == 0x0A)
					temp_w = 0; // newline
				else
					len_max = i; // coding error or max len (Exit after entering the display)
			}
			else if (encode == 2)
			{
				if (c[i] < 128 && c[i] > 0x00)
				temp_w = Ascii_w[c[i] - 0x20] + dis_x + 2;
				else if (c[i] >= 0xa1 && c[i + 1] >= 0x40)
					temp_w = W_Size + dis_x;
				else if (c[i] == 0x0A)
					temp_w = 0; // newline
				else
					len_max = i; // coding error or max len (Exit after entering the display)
			}

			// Displays a line of fonts, one by one from left to right
			if ((disp_w + temp_w) > W_Len || c[i] == 0x0A || i >= len_max) // Text box X-axis display coordinates out of range
			{
				data_w = disp_w; // Record width
				Y_start += H_Size;
				row_w[row_num++] = disp_w;

				if ((Y_start + H_Size) > H_Len)
					break; // Text box Y-axis is out of range
				disp_w = 0;
				if (i >= len_max)
					break;
				else if (c[i] == 0x0A)
				{
					i++;
				}
			}
			else  if (c[i] < 128 && c[i] > 0x00)
			{
				disp_w += (Ascii_w[c[i] - 0x20] + dis_x + 2);
				i++;
				j++;
			}
			else
			{
				if (encode == 0 && (c[i] >= 0xa1 && c[i] != 0xFF))
				{
					disp_w += (W_Size + dis_x);
					i += 2;
					j++;
				}
				else if (encode == 1 && (c[i] >= 0x81 && c[i + 1] >= 0x40 && c[i] != 0xFF))
				{
					disp_w += (W_Size + dis_x);
					i += 2;
					j++;
				}
				else if (encode == 2 && (c[i] >= 0xa1 && c[i + 1] >= 0x40))
				{
					disp_w += (W_Size + dis_x);
					i += 2;
					j++;
				}
			}
		}
	}
	else if (encode == 3 || encode == 6) // UNICODE
	{
		LT_ReadFlash_UI(buff_code, FlashAddr + 4, 4);
		start_code = buff_code[0] + (buff_code[1] << 8);
		end_code = buff_code[2] + (buff_code[3] << 8);
		font_byte = (W_Size * gray_bit + 7) / 8 * H_Size;
		while (1) // Automatic exit when meeting the end-of-transmission
		{
			unicode = (c[i] << 8) + c[i + 1];

			if (unicode == 0x0000)
				len_max = i;
			else if (unicode < 128 && unicode > 0x00)
				temp_w = Ascii_w[unicode - 0x20] + dis_x + 2;
			else if (unicode >= start_code && unicode <= end_code)
			{
				if (encode == 3)
					temp_w = W_Size + dis_x;
				else if (encode ==6)
				{
					LT_ReadFlash_UI(&unicode_w, FlashAddr + 104 + 95 * font_byte + (unicode - start_code) * (font_byte + 1), 1);
					temp_w = unicode_w + dis_x;
				}
			}
			else if (unicode == 0x000A)
				temp_w = 0; // newline
			else
				len_max = i; // coding error or max len (Exit after entering the display)

			// Displays a line of fonts, one by one from left to right
			if ((disp_w + temp_w) > W_Len || unicode == 0x000A || i >= len_max) // Text box X-axis display coordinates out of range
			{
				data_w = disp_w; // Record width
				Y_start += H_Size;
				row_w[row_num++] = disp_w;

				if ((Y_start + H_Size) > H_Len)
					break; // Text box Y-axis is out of range
				disp_w = 0;
				if (i >= len_max)
					break;
				else if (unicode == 0x000A)
				{
					i += 2;
				}
			}
			else if (unicode < 128 && unicode > 0x00)
			{
				disp_w += temp_w;
				i += 2;
				j++;
			}
			else if (unicode >= start_code && unicode <= end_code)
			{
				disp_w += temp_w;
				i += 2;
				j++;
			}
		}
	}
	else if (encode == 9) // gbk
	{
		LT_ReadFlash_UI(buff_code, FlashAddr + 4, 2);
		str_num = buff_code[0] + (buff_code[1] << 8);

		LT_ReadFlash_UI(DMA_rxbuf1, FlashAddr + 9, str_num * 2);
		font_byte = (W_Size * gray_bit + 7) / 8 * H_Size;
		while (1)
		{
			if (c[i] < 128 && c[i] > 0x00)
				unicode = c[i];
			else
				unicode = (c[i] << 8) + c[i + 1];

			for (k = 0; k < str_num; k++)
			{
				if (unicode == (DMA_rxbuf1[k * 2] + (DMA_rxbuf1[k * 2 + 1] << 8)))
				{
					break;
				}
			}

			if (k == str_num && unicode != 0x0A)
				len_max = i; // coding error or max len (Exit after entering the display)

			else if (k != str_num)
			{
				LT_ReadFlash_UI(&unicode_w, FlashAddr + 9 + str_num * 2 + k * (font_byte + 1), 1);
				if (unicode < 128 && unicode > 0x00)
					temp_w = unicode_w + dis_x + 2;
				else
					temp_w = unicode_w + dis_x;
			}

			if ((disp_w + temp_w) > W_Len || unicode == 0x0A || i >= len_max) // Text box X-axis display coordinates out of range
			{
				data_w = disp_w; // Record width
				Y_start += H_Size;
				row_w[row_num++] = disp_w;

				if ((Y_start + H_Size) > H_Len)
					break; // Text box Y-axis is out of range
				disp_w = 0;
				if (i >= len_max)
					break;
				else if (unicode == 0x0A)
					i++;
			}
			else if (unicode < 128 && unicode > 0x00)
			{
				disp_w += temp_w;
				i++;
				j++;
			}
			else
			{
				disp_w += temp_w;
				i += 2;
				j++;
			}
		}
	}

	if(text_mode == 2) return data_w; // display width

	if (text_mode == 1)
    {
        c = (uint8_t *)Display_buff_temp;
        if(encode == 3 || encode ==6)
        {
            for (i = 0; i < j; i++)
            {
                c[i * 2 ] = 0x00;
                c[i * 2 + 1] = 0x2a;
            }
			c[i * 2 ] = 0x00;     // '\0' 结束符
			c[i * 2 + 1] = 0x00;
            len_max = j * 2;
        }
        else
        {
            for (i = 0; i < j; i++)
            {
                c[i] = 0x2a;
            }
			c[i++] = 0x00;     // '\0'
			c[i++] = 0x00;
            len_max = j;
        }

        data_w = (Ascii_w['*' - 0x20] + dis_x + 2)*j; // Record width
//        disp_w = data_w;
    }

	i = 0;
	disp_w = 0;

	if (Screen_DIR == 0)
	{
		if (Alignment == 0 || Alignment == 3 || Alignment == 6)
			X_start = Xs;
		else if (Alignment == 1 || Alignment == 4 ||Alignment == 7)
			X_start = Xs + (W_Len - row_w[0]) / 2;
		else if (Alignment == 2 || Alignment == 5 || Alignment == 8)
			X_start = Xs + (W_Len - row_w[0]);
		if (Alignment == 0 || Alignment == 1 || Alignment == 2) // Align Center
		{
			Y_start = Ys + (H_Len - row_num * H_Size) / 2;
			x_src = Xs;
			y_src = Ys;
			w_real = W_Len;
			h_real = Y_start - Ys + H_Size;
		}
		else if (Alignment == 3 || Alignment == 4 || Alignment == 5) // Align up
		{
			Y_start = Ys;
			x_src = Xs;
			y_src = Ys;
			w_real = W_Len;
			h_real = H_Size;
		}
		else if (Alignment == 6 || Alignment == 7 || Alignment == 8) // Align down
		{
			Y_start = Ye - (row_num * H_Size);
			x_src = Xs;
			y_src = Ys;
			w_real = W_Len;
			h_real = (H_Len - row_num * H_Size) + H_Size;
		}
	}
	else if (Screen_DIR == 1)
	{
		if (Alignment == 0 || Alignment == 3  || Alignment == 6)
			Y_start = Ys;
		else if (Alignment == 1 || Alignment == 4 ||Alignment == 7)
			Y_start = Ys + (W_Len - row_w[0]) / 2;
		else if (Alignment == 2 || Alignment == 5 || Alignment == 8)
			Y_start = Ys + (W_Len - row_w[0]);

		if (Alignment == 0 || Alignment == 1 ||Alignment == 2) // Align  Center
		{
			X_start = Xs + row_num * H_Size + (H_Len - row_num * H_Size) / 2 - H_Size;
			x_src = Xs + (H_Len - row_num * H_Size) / 2 + row_num * H_Size - H_Size;
			y_src = Ys;
			w_real = (H_Len - row_num * H_Size) / 2 + H_Size;
			h_real = W_Len;
		}
		else if (Alignment == 3 || Alignment == 4 ||Alignment == 5) // Align  Up
		{
			X_start = Xe - H_Size;
			x_src = Xe - H_Size;
			y_src = Ys;
			w_real = H_Size;
			h_real = W_Len;
		}
		else if (Alignment == 6 || Alignment == 7 ||Alignment == 8) // Align  Down
		{
			X_start = Xs + (row_num - 1) * H_Size;;
			x_src = Xs + (row_num - 1) * H_Size;
			y_src = Ys;
			w_real = H_Len - (row_num - 1) * H_Size;
			h_real = W_Len;
		}
	}
	else if (Screen_DIR == 2)
	{
		if (Alignment == 0 || Alignment == 3 || Alignment == 6)
			X_start = Xe;
		else if (Alignment == 1 || Alignment == 4 ||Alignment == 7)
			X_start = Xe - (W_Len - row_w[0]) / 2;
		else if (Alignment == 2 || Alignment == 5 || Alignment == 8)
			X_start = Xs + row_w[0];
		if (Alignment == 0 || Alignment == 1 || Alignment == 2) // Align Center
		{
			Y_start = Ye - H_Size - (H_Len - row_num * H_Size) / 2;
			x_src = Xs;
			y_src = Ye - (H_Len - row_num * H_Size) / 2 - H_Size;
			w_real = W_Len;
			h_real = (H_Len - row_num * H_Size) / 2 + H_Size - 1;
		}
		else if (Alignment == 3 || Alignment == 4 || Alignment == 5) // Align up
		{
			Y_start = Ye - H_Size;
			x_src = Xs;
			y_src = Ye - H_Size ;
			w_real = W_Len;
			h_real = H_Size ;
		}
		else if (Alignment == 6 || Alignment == 7 || Alignment == 8) // Align down
		{
			Y_start = Ye - (H_Len - row_num * H_Size) - H_Size;
			x_src = Xs;
			y_src = Ye - (H_Len - row_num * H_Size) - H_Size;;
			w_real = W_Len;
			h_real = (H_Len - row_num * H_Size) + H_Size - 1;
		}
	}
	else if (Screen_DIR == 3)
	{
		if (Alignment == 0 || Alignment == 3 || Alignment == 6)
			Y_start = Ye;
		else if (Alignment == 1 || Alignment == 4 ||Alignment == 7)
			Y_start = Ye - (W_Len - row_w[0]) / 2;
		else if (Alignment == 2 || Alignment == 5 || Alignment == 8)
			Y_start = Ys + row_w[0] - 1;

		if (Alignment == 0 || Alignment == 1 ||Alignment == 2) // Align  Center
		{
			X_start = Xs + (H_Len - row_num * H_Size) / 2;
			x_src = Xs;
			y_src = Ys;
			w_real = (H_Len - row_num * H_Size) / 2 + H_Size;
			h_real = W_Len;
		}
		else if (Alignment == 3 || Alignment == 4 ||Alignment == 5) // Align  Up
		{
			X_start = Xs;
			x_src = Xs;
			y_src = Ys;
			w_real = H_Size;
			h_real = W_Len;
		}
		else if (Alignment == 6 || Alignment == 7 ||Alignment == 8) // Align  Down
		{
			X_start = Xe - row_num * H_Size;
			x_src = Xs;
			y_src = Ys;
			w_real = H_Len - (row_num - 1) * H_Size;
			h_real = W_Len;
		}
	}

	if (!enbackcolor)
	{
		if (mix == 0)
		{
			LT268_dispaly_CutPicture(x_src, y_src,
					x_src, y_src, w_real, h_real,
					FullScreen_W, FullScreen_addr, FullScreen_color, FullScreen_flag);
		}
		else if(mix == 1)
		{
			LT268_dispaly_CutPicture(x_src, y_src,
				x_src - mixpic.x, y_src - mixpic.y, w_real, h_real,
				mixpic.w, mixpic.addr, mixpic.len, mixpic.flag);
		}
	}
	else
	{
		LT268_TFT_FillColor(x_src, y_src, w_real, h_real, BackColor);
	}

	// display
	row = 0;
	x_des = X_start;
	y_des = Y_start;

	if (encode == 0 || encode == 1 || encode == 2 || encode == 4) // ASCII GB2312 GBK BIG5
	{
		if (encode == 0)		//GB2312
		{
			scode = 0xa1;
			ecode = 0x00;
		}
		else if (encode == 1)	//GBK
		{
			scode = 0x81;
			ecode = 0x40;
		}
		else if (encode == 2)	//BIG5
		{
			scode = 0xa1;
			ecode = 0x40;
		}
		else if (encode == 4)	//ASCII
		{
			scode = 0xff;
			ecode = 0xff;
		}

		while (1) // Automatic exit when meeting the end-of-transmission
		{
			if (c[i] < 128 && c[i] > 0x00)
				disp_w = Ascii_w[c[i] - 0x20]  + dis_x + 2;
			else if (c[i] >= scode && c[i + 1] >= ecode && c[i] != 0xFF)
				disp_w = W_Size + dis_x;

			if (len_disp + disp_w > W_Len || c[i] == 0x0a)
			{
				row++;
				len_disp = 0;
				offset_disp += H_Size;

				if (offset_disp + H_Size > H_Len)
					break;

				if (Screen_DIR == 0)
				{
					if (Alignment == 0  || Alignment == 3 || Alignment == 6 )
						x_des = Xs;
					else if (Alignment == 1 || Alignment == 4 || Alignment == 7)
						x_des = Xs + (W_Len - row_w[row]) / 2;
					else if (Alignment == 2 || Alignment == 5 || Alignment == 8)
						x_des = Xs + (W_Len - row_w[row]);

					y_des = Y_start + offset_disp;
					x_src = Xs;
					y_src = Y_start + offset_disp;
					w_real = W_Len;
					h_real = H_Size;
				}
				else if (Screen_DIR == 1)
				{
					if (Alignment == 0  || Alignment == 3 || Alignment == 6 )
						y_des = Ys;
					else if (Alignment == 1 || Alignment == 4 || Alignment == 7)
						y_des = Ys + (W_Len - row_w[row]) / 2;
					else if (Alignment == 2 || Alignment == 5 || Alignment == 8)
						y_des = Ys + (W_Len - row_w[row]);

					x_des = X_start - offset_disp;
					x_src = X_start - offset_disp;
					y_src = Ys;
					w_real = H_Size;
					h_real = W_Len;
				}
				else if (Screen_DIR == 2)
				{
					if (Alignment == 0  || Alignment == 3 || Alignment == 6 )
						x_des = Xe;
					else if (Alignment == 1 || Alignment == 4 || Alignment == 7)
						x_des = Xe - (W_Len - row_w[row]) / 2;
					else if (Alignment == 2 || Alignment == 5 || Alignment == 8)
						x_des = Xs + row_w[row];

					y_des = Y_start - offset_disp;
					x_src = Xs;
					y_src = Y_start - offset_disp;
					w_real = W_Len;
					h_real = H_Size;
				}
				else if (Screen_DIR == 3)
				{
					if (Alignment == 0  || Alignment == 3 || Alignment == 6 )
						y_des = Ye;
					else if (Alignment == 1 || Alignment == 4 || Alignment == 7)
						y_des = Ye - (W_Len - row_w[row]) / 2;
					else if (Alignment == 2 || Alignment == 5 || Alignment == 8)
						y_des = Ys + row_w[row] - 1;

					x_des = X_start + offset_disp;
					x_src = X_start + offset_disp;
					y_src = Ys;
					w_real = H_Size;
					h_real = W_Len;
				}
#if !LT_PSRAM
				if (!enbackcolor)
				{
					if (mix == 0)
					{
						LT268_dispaly_CutPicture(x_src, y_src,
								x_src, y_src, w_real, h_real,
								FullScreen_W, FullScreen_addr, FullScreen_color, FullScreen_flag);
					}
					else if(mix == 1)
						LT268_dispaly_CutPicture(x_src, y_src,
							Xs - mixpic.x, Ys - mixpic.y, w_real, h_real,
							mixpic.w, mixpic.addr, mixpic.len, mixpic.flag);
				}
				else
				{
					LT268_TFT_FillColor(x_src, y_src, w_real, h_real, BackColor);
				}
#endif
				if (c[i] == 0x0a)
				{
					i++;
					if (i >= len_max)
						break;
					continue;
				}
			}

			if (c[i] < 128 && c[i] > 0x00)
			{
#if LT_PSRAM
				LT268_GrayScaleFont_dislay(4, ShowAddr, FlashAddr, W_Size, H_Size, gray,
											FontColor, BackColor, enbackcolor, mix, mixpic,
											x_des - Xs, y_des - Ys, Ascii_w[c[i] - 0x20] + dis_x + 2, &c[i], Xe - Xs + 1);
#else
				LT268_GrayScaleFont_dislay(4, ShowAddr, FlashAddr, W_Size, H_Size, gray,
											FontColor, BackColor, enbackcolor, mix, mixpic,
											x_des, y_des, Ascii_w[c[i] - 0x20] + dis_x + 2, &c[i], Xe - Xs + 1);
#endif
				if (Screen_DIR == 0)
					x_des += (Ascii_w[c[i] - 0x20] + dis_x + 2);
				else if (Screen_DIR == 1)
					y_des += (Ascii_w[c[i] - 0x20] + dis_x + 2);
				else if (Screen_DIR == 2)
					x_des -= (Ascii_w[c[i] - 0x20] + dis_x + 2);
				else if (Screen_DIR == 3)
					y_des -= (Ascii_w[c[i] - 0x20] + dis_x + 2);

				len_disp += (Ascii_w[c[i] - 0x20] + dis_x + 2);
				i++;
				if (i >= len_max)
					break;
			}
			else if (c[i] >= scode && c[i + 1] >= ecode && c[i] != 0xFF)
			{
#if LT_PSRAM
				LT268_GrayScaleFont_dislay(encode, ShowAddr, FlashAddr, W_Size, H_Size, gray,
											FontColor, BackColor, enbackcolor, mix, mixpic,
											x_des - Xs, y_des - Ys, W_Size + dis_x, &c[i], Xe - Xs + 1);
#else
				LT268_GrayScaleFont_dislay(encode, ShowAddr, FlashAddr, W_Size, H_Size, gray,
															FontColor, BackColor, enbackcolor, mix, mixpic,
															x_des, y_des, W_Size + dis_x, &c[i], Xe - Xs + 1);
#endif

				if (Screen_DIR == 0)
					x_des += (W_Size + dis_x);
				else if (Screen_DIR == 1)
					y_des += (W_Size + dis_x);
				else if (Screen_DIR == 2)
					x_des -= (W_Size + dis_x);
				else if (Screen_DIR == 3)
					y_des -= (W_Size + dis_x);

				len_disp += (W_Size + dis_x);
				i += 2;
				if (i >= len_max)
					break;
			}
			if (i >= len_max)
				break;
		}
	}
	else if (encode == 3 || encode == 6) // unicode
	{
		font_byte = (W_Size * gray_bit + 7) / 8 * H_Size;
		LT_ReadFlash_UI(buff_code, FlashAddr + 4, 4);
		scode = buff_code[0] + (buff_code[1] << 8);
		ecode = buff_code[2] + (buff_code[3] << 8);

		while (1) // Automatic exit when meeting the end-of-transmission
		{
			unicode = (c[i] << 8) + c[i + 1];

			if (unicode < 128 && unicode > 0x00)
				disp_w = Ascii_w[unicode- 0x20]  + dis_x + 2;
			else if (unicode >= scode && unicode <= ecode)
			{
				if (encode == 3)
					disp_w = W_Size + dis_x;
				else if (encode == 6)
				{
					LT_ReadFlash_UI(&unicode_w, FlashAddr + 104 + 95 * font_byte + (unicode - scode) * (font_byte + 1), 1);
					disp_w = unicode_w + dis_x;
				}
			}

			if (len_disp + disp_w > W_Len || unicode == 0x0a)
			{
				row++;
				len_disp = 0;
				offset_disp += H_Size;

				if (offset_disp + H_Size > H_Len)
					break;

				if (Screen_DIR == 0)
				{
					if (Alignment == 0  || Alignment == 3 || Alignment == 6 )
						x_des = Xs;
					else if (Alignment == 1 || Alignment == 4 || Alignment == 7)
						x_des = Xs + (W_Len - row_w[row]) / 2;
					else if (Alignment == 2 || Alignment == 5 || Alignment == 8)
						x_des = Xs + (W_Len - row_w[row]);

					y_des = Y_start + offset_disp;
					x_src = Xs;
					y_src = Y_start + offset_disp;
					w_real = W_Len;
					h_real = H_Size;
				}
				else if (Screen_DIR == 1)
				{
					if (Alignment == 0  || Alignment == 3 || Alignment == 6 )
						y_des = Ys;
					else if (Alignment == 1 || Alignment == 4 || Alignment == 7)
						y_des = Ys + (W_Len - row_w[row]) / 2;
					else if (Alignment == 2 || Alignment == 5 || Alignment == 8)
						y_des = Ys + (W_Len - row_w[row]);

					x_des = X_start - offset_disp;
					x_src = X_start - offset_disp;
					y_src = Ys;
					w_real = H_Size;
					h_real = W_Len;
				}
				else if (Screen_DIR == 2)
				{
					if (Alignment == 0  || Alignment == 3 || Alignment == 6 )
						x_des = Xe;
					else if (Alignment == 1 || Alignment == 4 || Alignment == 7)
						x_des = Xe - (W_Len - row_w[row]) / 2;
					else if (Alignment == 2 || Alignment == 5 || Alignment == 8)
						x_des = Xs + row_w[row];

					y_des = Y_start - offset_disp;
					x_src = Xs;
					y_src = Y_start - offset_disp;
					w_real = W_Len;
					h_real = H_Size;
				}
				else if (Screen_DIR == 3)
				{
					if (Alignment == 0  || Alignment == 3 || Alignment == 6 )
						y_des = Ye;
					else if (Alignment == 1 || Alignment == 4 || Alignment == 7)
						y_des = Ye - (W_Len - row_w[row]) / 2;
					else if (Alignment == 2 || Alignment == 5 || Alignment == 8)
						y_des = Ys + row_w[row] - 1;

					x_des = X_start + offset_disp;
					x_src = X_start + offset_disp;
					y_src = Ys;
					w_real = H_Size;
					h_real = W_Len;
				}
#if !LT_PSRAM
				if (!enbackcolor)
				{
					if (mix == 0)
					{
						LT268_dispaly_CutPicture(x_src, y_src,
								x_src, y_src, w_real, h_real,
								FullScreen_W, FullScreen_addr, FullScreen_color, FullScreen_flag);
					}
					else if(mix == 1)
						LT268_dispaly_CutPicture(x_src, y_src,
							Xs - mixpic.x, Ys - mixpic.y, w_real, h_real,
							mixpic.w, mixpic.addr, mixpic.len, mixpic.flag);
				}
				else
				{
					LT268_TFT_FillColor(x_src, y_src, w_real, h_real, BackColor);
				}
#endif
				if (unicode == 0x0a)
				{
					i++;
					if (i >= len_max)
						break;
					continue;
				}
			}

			if (unicode< 128 && unicode > 0x00)
			{
#if LT_PSRAM
				LT268_GrayScaleFont_dislay(4, ShowAddr, FlashAddr, W_Size, H_Size, gray,
											FontColor, BackColor, enbackcolor, mix, mixpic,
											x_des - Xs, y_des - Ys, Ascii_w[unicode - 0x20] + dis_x + 2, &c[i + 1], Xe - Xs + 1);
#else
				LT268_GrayScaleFont_dislay(4, ShowAddr, FlashAddr, W_Size, H_Size, gray,
															FontColor, BackColor, enbackcolor, mix, mixpic,
															x_des, y_des, Ascii_w[unicode - 0x20] + dis_x + 2, &c[i + 1], Xe - Xs + 1);
#endif
				if (Screen_DIR == 0)
					x_des += (Ascii_w[unicode - 0x20] + dis_x + 2);
				else if (Screen_DIR == 1)
					y_des += (Ascii_w[unicode - 0x20] + dis_x + 2);
				else if (Screen_DIR == 2)
					x_des -= (Ascii_w[unicode - 0x20] + dis_x + 2);
				else if (Screen_DIR == 3)
					y_des -= (Ascii_w[unicode - 0x20] + dis_x + 2);

				len_disp += (Ascii_w[unicode - 0x20] + dis_x + 2);
				i+=2;
				if (i >= len_max)
					break;
			}
			else if (unicode >= scode && unicode <= ecode)
			{
				unicode_temp = unicode - scode;
#if LT_PSRAM
				LT268_GrayScaleFont_dislay(encode, ShowAddr, FlashAddr, W_Size, H_Size, gray,
											FontColor, BackColor, enbackcolor, mix, mixpic,
											x_des - Xs, y_des - Ys, disp_w, (uint8_t *)(&unicode_temp), Xe - Xs + 1);
#else
				LT268_GrayScaleFont_dislay(encode, ShowAddr, FlashAddr, W_Size, H_Size, gray,
											FontColor, BackColor, enbackcolor, mix, mixpic,
											x_des, y_des, disp_w, (uint8_t *)(&unicode_temp), Xe - Xs + 1);
#endif
				if (Screen_DIR == 0)
					x_des += disp_w;
				else if (Screen_DIR == 1)
					y_des += disp_w;
				else if (Screen_DIR == 2)
					x_des -= disp_w;
				else if (Screen_DIR == 3)
					y_des -= disp_w;

				len_disp += disp_w;
				i += 2;
				if (i >= len_max)
					break;
			}
			if (i >= len_max)
				break;
		}
	}
	else if (encode == 9) // str
	{
		font_byte = (W_Size * gray_bit + 7) / 8 * H_Size;

		LT_ReadFlash_UI(buff_code, FlashAddr + 4, 2);
		str_num = buff_code[0] + (buff_code[1] << 8);

		LT_ReadFlash_UI(DMA_rxbuf1, FlashAddr + 9, str_num * 2);

		while (1) // Automatic exit when meeting the end-of-transmission
		{
			if (c[i] < 128 && c[i] > 0x00)
				unicode = c[i];
			else
				unicode = (c[i] << 8) + c[i + 1];

			for(k = 0; k < str_num; k++)
			{
				if (unicode == (DMA_rxbuf1[k*2] + (DMA_rxbuf1[k*2 + 1] <<  8)))
				{
					LT_ReadFlash_UI(&unicode_w, FlashAddr + 9 + str_num * 2 + k * (font_byte + 1) , 1);
					if (unicode< 128 && unicode > 0x00)
						disp_w = unicode_w + dis_x + 2;
					else
						disp_w = unicode_w + dis_x;
					break;
				}
			}

			if (len_disp + disp_w > W_Len || unicode == 0x0a)
			{
				row++;
				len_disp = 0;
				offset_disp += H_Size;

				if (offset_disp + H_Size > H_Len)
					break;

				if (Screen_DIR == 0)
				{
					if (Alignment == 0  || Alignment == 3 || Alignment == 6 )
						x_des = Xs;
					else if (Alignment == 1 || Alignment == 4 || Alignment == 7)
						x_des = Xs + (W_Len - row_w[row]) / 2;
					else if (Alignment == 2 || Alignment == 5 || Alignment == 8)
						x_des = Xs + (W_Len - row_w[row]);

					y_des = Y_start + offset_disp;
					x_src = Xs;
					y_src = Y_start + offset_disp;
					w_real = W_Len;
					h_real = H_Size;
				}
				else if (Screen_DIR == 1)
				{
					if (Alignment == 0  || Alignment == 3 || Alignment == 6 )
						y_des = Ys;
					else if (Alignment == 1 || Alignment == 4 || Alignment == 7)
						y_des = Ys + (W_Len - row_w[row]) / 2;
					else if (Alignment == 2 || Alignment == 5 || Alignment == 8)
						y_des = Ys + (W_Len - row_w[row]);

					x_des = X_start - offset_disp;
					x_src = X_start - offset_disp;
					y_src = Ys;
					w_real = H_Size;
					h_real = W_Len;
				}
				else if (Screen_DIR == 2)
				{
					if (Alignment == 0  || Alignment == 3 || Alignment == 6 )
						x_des = Xe;
					else if (Alignment == 1 || Alignment == 4 || Alignment == 7)
						x_des = Xe - (W_Len - row_w[row]) / 2;
					else if (Alignment == 2 || Alignment == 5 || Alignment == 8)
						x_des = Xs + row_w[row];

					y_des = Y_start - offset_disp;
					x_src = Xs;
					y_src = Y_start - offset_disp;
					w_real = W_Len;
					h_real = H_Size;
				}
				else if (Screen_DIR == 3)
				{
					if (Alignment == 0  || Alignment == 3 || Alignment == 6 )
						y_des = Ye;
					else if (Alignment == 1 || Alignment == 4 || Alignment == 7)
						y_des = Ye - (W_Len - row_w[row]) / 2;
					else if (Alignment == 2 || Alignment == 5 || Alignment == 8)
						y_des = Ys + row_w[row] - 1;

					x_des = X_start + offset_disp;
					x_src = X_start + offset_disp;
					y_src = Ys;
					w_real = H_Size;
					h_real = W_Len;
				}
#if !LT_PSRAM
				if (!enbackcolor)
				{
					if (mix == 0)
					{
						LT268_dispaly_CutPicture(x_src, y_src,
								x_src, y_src, w_real, h_real,
								FullScreen_W, FullScreen_addr, FullScreen_color, FullScreen_flag);

					}
					else if(mix == 1)
						LT268_dispaly_CutPicture(x_src, y_src,
							Xs - mixpic.x, Ys - mixpic.y, w_real, h_real,
							mixpic.w, mixpic.addr, mixpic.len, mixpic.flag);
				}
				else
				{
					LT268_TFT_FillColor(x_src, y_src, w_real, h_real, BackColor);
				}
#endif

				if (unicode == 0x0a)
				{
					i++;
				}
			}

			if (unicode != 0x0A)
			{
				unicode_temp = k;
#if LT_PSRAM
				LT268_GrayScaleFont_dislay(encode, ShowAddr, FlashAddr + 9 + str_num * 2, W_Size, H_Size, gray,
											FontColor, BackColor, enbackcolor, mix, mixpic,
											x_des - Xs, y_des - Ys, disp_w, (uint8_t *)(&unicode_temp), Xe - Xs + 1);
#else
				LT268_GrayScaleFont_dislay(encode, ShowAddr, FlashAddr + 9 + str_num * 2, W_Size, H_Size, gray,
											FontColor, BackColor, enbackcolor, mix, mixpic,
											x_des, y_des, disp_w, (uint8_t *)(&unicode_temp), Xe - Xs + 1);
#endif

				if (Screen_DIR == 0)
					x_des += disp_w;
				else if (Screen_DIR == 1)
					y_des += disp_w;
				else if (Screen_DIR == 2)
					x_des -= disp_w;
				else if (Screen_DIR == 3)
					y_des -= disp_w;

				len_disp += disp_w;
				if (unicode < 128 && unicode > 0x00)
					i++;
				else
					i += 2;
				if (i >= len_max)
					break;
			}
			if (i >= len_max)
				break;
		}
	}

	if (Screen_DIR == 0)
	{
		if (Alignment == 0 || Alignment == 1 || Alignment == 2)	// Align Center
		{
			x_src = Xs;
			y_src = Ye - (H_Len - row_num * H_Size) / 2;
			w_real = W_Len;
			h_real = (H_Len - row_num * H_Size) / 2;
		}
		else if (Alignment == 3 || Alignment == 4 || Alignment == 5)	// Align Up
		{
			x_src = Xs;
			y_src = Ys + (row_num * H_Size);
			w_real = W_Len;
			h_real = H_Len - row_num * H_Size;
		}
		else if(Alignment == 6 || Alignment == 7 || Alignment == 8)
		{
			w_real = 0;
			h_real = 0;
		}
	}
	else if (Screen_DIR == 1)
	{
		if (Alignment == 0 || Alignment == 1 || Alignment == 2)			// Align Center
		{
			x_src = Xs;
			y_src = Ys;
			w_real = (H_Len - row_num * H_Size) / 2 ;
			h_real = W_Len;
		}
		else if (Alignment == 3 || Alignment == 4 || Alignment == 5) 	// Align Up
		{
			x_src = Xs;
			y_src = Ys;
			w_real = H_Len - row_num * H_Size ;
			h_real = W_Len;
		}
		else if (Alignment == 6 || Alignment == 7 || Alignment == 8)	// Align Down
		{
			w_real = 0;
			h_real = 0;
		}
	}
	else if (Screen_DIR == 2)
	{
		if (Alignment == 0 || Alignment == 1 || Alignment == 2)			// Align Center
		{
			x_src = Xs;
			y_src = Ys;
			w_real = W_Len;
			h_real = (H_Len - row_num * H_Size) / 2;
		}
		else if (Alignment == 3 || Alignment == 4 || Alignment == 5) 	// Align Up
		{
			x_src = Xs;
			y_src = Ys;
			w_real = W_Len;
			h_real = H_Len - row_num * H_Size ;
		}
		else if (Alignment == 6 || Alignment == 7 || Alignment == 8)	// Align Down
		{
			w_real = 0;
			h_real = 0;
		}
	}
	else if (Screen_DIR == 3)
	{
		if (Alignment == 0 || Alignment == 1 || Alignment == 2)			// Align Center
		{
			x_src = Xe - (H_Len - row_num * H_Size) / 2;
			y_src = Ys;
			w_real = (H_Len - row_num * H_Size) / 2 ;
			h_real = W_Len;
		}
		else if (Alignment == 3 || Alignment == 4 || Alignment == 5) 	// Align Up
		{
			x_src = Xs + row_num * H_Size;
			y_src = Ys;
			w_real = H_Len - row_num * H_Size ;
			h_real = W_Len;
		}
		else if (Alignment == 6 || Alignment == 7 || Alignment == 8)	// Align Down
		{
			w_real = 0;
			h_real = 0;
		}
	}

	if (w_real != 0  && h_real != 0)
	{
		if (!enbackcolor)
		{
			if (mix == 0)
			{
				LT268_dispaly_CutPicture(x_src, y_src,
						x_src, y_src, w_real, h_real,
						FullScreen_W, FullScreen_addr, FullScreen_color, FullScreen_flag);
			}
			else if(mix == 1)
				LT268_dispaly_CutPicture(x_src, y_src,
					Xs - mixpic.x, Ys - mixpic.y, w_real, h_real,
					mixpic.w, mixpic.addr, mixpic.len, mixpic.flag);
		}
		else
		{
			LT268_TFT_FillColor(x_src, y_src, w_real, h_real, BackColor);
		}
	}
}

/*******************************************************************************
 * Function Name : LT_Print_zk_Font_BUFF
 * Description   : Buffer a string.
 * Input         :
 * Output        : None
 * Return        : None
 ********************************************************************/
uint16_t LT_Print_zk_Font_BUFF(
	uint16_t encode // encoding type     0:GB2312  1:GBK  2:BIG5  3:UNICODE  4:ASCII
	,
	uint32_t FlashAddr // Font source address(exSpiFlash)
	,
	uint32_t ShowAddr // Displays the address of the layer
	,
	uint16_t width // Display the width of the layer
	,
	uint8_t W_Size // font width
	,
	uint8_t H_Size // font height
	,
	uint8_t Alignment // Alignment
	,
	uint32_t FontColor // The foreground color of the font
	,
	uint32_t BackColor // The background color of the font
	,
	uint8_t enbackcolor // Background color enable, 0:disable  1:enable
	//,uint16_t mix // mix mode, 0:with fullscreen interface   1:with specific pictures(Text box needs to be fully included)
	//,_PICINFO mixpic // mix picture info
	,
	uint16_t buf_w // width of buffer
	,
	uint16_t buf_h // height of buffer
	,
	uint8_t *buf // address of buffer
	,
	uint16_t buf_x // start x of buffer
	,
	uint16_t buf_y // start y of buffer
	,
	uint16_t text_W //
	,
	uint16_t text_H //
	,
	uint8_t dis_x // The interval between two adjacent fonts on the x-axis
	,
	uint8_t dis_y // The interval between two adjacent fonts on the y-axis
	,
	uint8_t *c // Address of text
	,
	uint16_t len_max // max lenght of text
)
{
	uint16_t temp = 0, temp_H = 0, temp_L = 0;
	uint16_t X_start = 0, Y_start = 0;
	uint32_t i = 0;
	uint8_t gray, gray_bit;
	uint16_t disp_w = 0, disp_i = 0;
	uint16_t len_disp = 0, offset_disp = 0 , W_Len = 0, H_Len = 0;
	uint16_t temp_w, box_w = 0;
	uint16_t row = 0, row_num = 0, row_w[20]; // max line = 20
	uint8_t unicode_w;
	uint16_t font_byte; // bytes of a single font
	uint16_t scode,ecode;
	uint16_t x_des = 0, y_des = 0;

	uint16_t unicode = 0, unicode_temp = 0;
	uint16_t start_code = 0, end_code = 0;
	uint8_t buff_code[4];
	uint16_t str_num,k;

	LT_ReadFlash_UI(Ascii_w, FlashAddr + 9, 95);
	LT_ReadFlash_UI(&gray, FlashAddr + 8, 1);
//	LTPrintf("encode %d gray %d  %d \r\n",encode,gray,Ascii_w[0x30-0x20]);

	if (gray == 0)
		gray_bit = 1;
	else if (gray == 1)
		gray_bit = 2;
	else if (gray == 2)
		gray_bit = 4;

	if (Screen_DIR == 0 || Screen_DIR == 2)
	{
		W_Len = text_W;
		H_Len = text_H;
	}
	else if (Screen_DIR == 1 || Screen_DIR == 3)
	{
		W_Len = text_H;
		H_Len = text_W;
	}

	i = 0;

	if (encode == 4 || encode == 0 || encode == 1 || encode == 2) // ASCII GB2312 GBK BIG5
	{
		while (1) // Automatic exit when meeting the end-of-transmission
		{
			if (encode == 4)
			{
				if (c[i] < 128 && c[i] > 0x00)
					temp_w = (Ascii_w[c[i] - 0x20] + dis_x + 2);
				else if (c[i] == 0x0A)
					temp_w = 0; // newline
				else
					len_max = i; // coding error or max len (Exit after entering the display)
			}
			else if (encode == 0)
			{
				if (c[i] < 128 && c[i] > 0x00)
				temp_w = Ascii_w[c[i] - 0x20] + dis_x + 2;
				else if (c[i] >= 0xa1 && c[i] != 0xFF)
					temp_w = W_Size + dis_x;
				else if (c[i] == 0x0A)
					temp_w = 0; // newline
				else
					len_max = i; // coding error or max len (Exit after entering the display)
			}
			else if (encode == 1)
			{
				if (c[i] < 128 && c[i] > 0x00)
					temp_w = Ascii_w[c[i] - 0x20] + dis_x + 2;
				else if (c[i] >= 0x81 && c[i + 1] >= 0x40 && c[i] != 0xFF)
					temp_w = W_Size + dis_x;
				else if (c[i] == 0x0A)
					temp_w = 0; // newline
				else
					len_max = i; // coding error or max len (Exit after entering the display)
			}
			else if (encode == 2)
			{
				if (c[i] < 128 && c[i] > 0x00)
				temp_w = Ascii_w[c[i] - 0x20] + dis_x + 2;
				else if (c[i] >= 0xa1 && c[i + 1] >= 0x40)
					temp_w = W_Size + dis_x;
				else if (c[i] == 0x0A)
					temp_w = 0; // newline
				else
					len_max = i; // coding error or max len (Exit after entering the display)
			}

			// Displays a line of fonts, one by one from left to right
			if ((disp_w + temp_w) > W_Len || c[i] == 0x0A || i >= len_max) // Text box X-axis display coordinates out of range
			{
				data_w = disp_w; // Record width
				Y_start += H_Size;
				row_w[row_num++] = disp_w;

				if ((Y_start + H_Size) > H_Len)
					break; // Text box Y-axis is out of range
				disp_w = 0;
				if (i >= len_max)
					break;
				else if (c[i] == 0x0A)
				{
					i++;
				}
			}
			else  if (c[i] < 128 && c[i] > 0x00)
			{
				disp_w += (Ascii_w[c[i] - 0x20] + dis_x + 2);
				i++;
			}
			else
			{
				if (encode == 0 && (c[i] >= 0xa1 && c[i] != 0xFF))
				{
					disp_w += (W_Size + dis_x);
					i += 2;

				}
				else if (encode == 1 && (c[i] >= 0x81 && c[i + 1] >= 0x40 && c[i] != 0xFF))
				{
					disp_w += (W_Size + dis_x);
					i += 2;

				}
				else if (encode == 2 && (c[i] >= 0xa1 && c[i + 1] >= 0x40))
				{
					disp_w += (W_Size + dis_x);
					i += 2;

				}
			}
		}
	}
	else if (encode == 3 || encode == 6) // UNICODE
	{
		LT_ReadFlash_UI(buff_code, FlashAddr + 4, 4);
		start_code = buff_code[0] + (buff_code[1] << 8);
		end_code = buff_code[2] + (buff_code[3] << 8);
		font_byte = (W_Size * gray_bit + 7) / 8 * H_Size;
		while (1) // Automatic exit when meeting the end-of-transmission
		{
			unicode = (c[i] << 8) + c[i + 1];

			if (unicode == 0x0000)
				len_max = i;
			else if (unicode < 128 && unicode > 0x00)
				temp_w = Ascii_w[unicode - 0x20] + dis_x + 2;
			else if (unicode >= start_code && unicode <= end_code)
			{
				if (encode == 3)
					temp_w = W_Size + dis_x;
				else if (encode ==6)
				{
					LT_ReadFlash_UI(&unicode_w, FlashAddr + 104 + 95 * font_byte + (unicode - start_code) * (font_byte + 1), 1);
					temp_w = unicode_w + dis_x;
				}
			}
			else if (unicode == 0x0A)
				temp_w = 0; // newline
			else
				len_max = i; // coding error or max len (Exit after entering the display)

			// Displays a line of fonts, one by one from left to right
			if ((disp_w + temp_w) > W_Len || unicode == 0x0A || i >= len_max) // Text box X-axis display coordinates out of range
			{
				data_w = disp_w; // Record width
				Y_start += H_Size;
				row_w[row_num++] = disp_w;

				if ((Y_start + H_Size) > H_Len)
					break; // Text box Y-axis is out of range
				disp_w = 0;
				if (i >= len_max)
					break;
				else if (unicode == 0x0A)
				{
					i += 2;
				}
			}
			else if (unicode < 128 && unicode > 0x00)
			{
				disp_w += temp_w;
				i += 2;

			}
			else if (unicode >= start_code && unicode <= end_code)
			{
				disp_w += temp_w;
				i += 2;

			}
		}
	}
	else if (encode == 9)
	{
		LT_ReadFlash_UI(buff_code, FlashAddr + 4, 2);
		str_num = buff_code[0] + (buff_code[1] << 8);

		LT_ReadFlash_UI(DMA_rxbuf1, FlashAddr + 9, str_num * 2);
		font_byte = (W_Size * gray_bit + 7) / 8 * H_Size;
		while(1)
		{
			if (c[i] < 128 && c[i] > 0x00)
				unicode = c[i];
			else
				unicode = (c[i] << 8) + c[i + 1];

			for(k = 0; k < str_num; k++)
			{
				if (unicode == (DMA_rxbuf1[k*2] + (DMA_rxbuf1[k*2 + 1] <<  8)))
				{
					break;
				}
			}
			if (k == str_num && unicode != 0x0A)
				len_max = i; // coding error or max len (Exit after entering the display)

			else if (k != str_num)
			{
				LT_ReadFlash_UI(&unicode_w, FlashAddr + 8 + str_num * 2 + k * (font_byte + 1) + 1, 1);
				if (unicode< 128 && unicode > 0x00)
					temp_w = unicode_w + dis_x + 2;
				else
					temp_w = unicode_w + dis_x;
			}

			if ((disp_w + temp_w) > W_Len || c[i] == 0x0A || i >= len_max) // Text box X-axis display coordinates out of range
			{
				data_w = disp_w; // Record width
				Y_start += H_Size;
				row_w[row_num++] = disp_w;

				if ((Y_start + H_Size) > H_Len)
					break; // Text box Y-axis is out of range
				disp_w = 0;
				if (i >= len_max)
					break;
				else if (unicode == 0x000A)
					i ++;
			}
			else if (unicode < 128 && unicode > 0x00)
			{
				disp_w += temp_w;
				i++;
			}
			else
			{
				disp_w += temp_w;
				i+=2;
			}
		}
	}

	i = 0;
	disp_w = 0;
	if(Alignment > 8)
	{
		if (Screen_DIR == 0)
		{
			Y_start = buf_y;
			if (Alignment == 9)
				X_start = buf_x;
			else if (Alignment == 10)
				X_start = buf_x - row_w[0] / 2 + 1;
			else if (Alignment == 11)
				X_start = buf_x - row_w[0] + 1;
		}
		else if (Screen_DIR == 1)
		{
			X_start = buf_x - H_Size;
			if (Alignment == 9)
				Y_start = buf_y;
			else if (Alignment == 10)
				Y_start = buf_y - row_w[0] / 2 + 1;
			else if (Alignment == 11)
				Y_start = buf_y - row_w[0] + 1;
		}
		else if (Screen_DIR == 2)
		{
			Y_start = buf_y - H_Size + 1;
			if (Alignment == 9)
				X_start = buf_x;
			else if (Alignment == 10)
				X_start = buf_x + row_w[0] / 2;
			else if (Alignment == 11)
				X_start = buf_x + row_w[0];
		}
		else if (Screen_DIR == 3)
		{
			X_start = buf_x;
			if (Alignment == 9)
				Y_start = buf_y;
			else if (Alignment == 10)
				Y_start = buf_y + row_w[0] / 2;
			else if (Alignment == 11)
				Y_start = buf_y + row_w[0];
		}
	}
	else
	{
		if (Screen_DIR == 0)
		{
			if (Alignment == 0 || Alignment == 3 || Alignment == 6)
				X_start = buf_x;
			else if (Alignment == 1 || Alignment == 4 ||Alignment == 7)
				X_start = buf_x + (W_Len - row_w[0]) / 2;
			else if (Alignment == 2 || Alignment == 5 || Alignment == 8)
				X_start = buf_x + (W_Len - row_w[0]);
			if (Alignment == 0 || Alignment == 1 || Alignment == 2) // Align Center
			{
				Y_start = buf_y + (H_Len - row_num * H_Size) / 2;
			}
			else if (Alignment == 3 || Alignment == 4 || Alignment == 5) // Align up
			{
				Y_start = buf_y;
			}
			else if (Alignment == 6 || Alignment == 7 || Alignment == 8) // Align down
			{
				Y_start = buf_y + H_Len - (row_num * H_Size);
			}
		}
		else if (Screen_DIR == 1)
		{
			if (Alignment == 0 || Alignment == 3  || Alignment == 6)
				Y_start = buf_y;
			else if (Alignment == 1 || Alignment == 4 ||Alignment == 7)
				Y_start = buf_y + (W_Len - row_w[0]) / 2;
			else if (Alignment == 2 || Alignment == 5 || Alignment == 8)
				Y_start = buf_y + (W_Len - row_w[0]);

			if (Alignment == 0 || Alignment == 1 ||Alignment == 2) // Align  Center
			{
				X_start = buf_x + row_num * H_Size + (H_Len - row_num * H_Size) / 2 - H_Size;
			}
			else if (Alignment == 3 || Alignment == 4 ||Alignment == 5) // Align  Up
			{
				X_start = buf_x + H_Len - H_Size;//Xe - H_Size;
			}
			else if (Alignment == 6 || Alignment == 7 ||Alignment == 8) // Align  Down
			{
				X_start = buf_x + (row_num - 1) * H_Size;
			}
		}
		else if (Screen_DIR == 2)
		{
			if (Alignment == 0 || Alignment == 3 || Alignment == 6)
				X_start = buf_x + W_Len;
			else if (Alignment == 1 || Alignment == 4 ||Alignment == 7)
				X_start = buf_x + W_Len - (W_Len - row_w[0]) / 2;
			else if (Alignment == 2 || Alignment == 5 || Alignment == 8)
				X_start = buf_x + row_w[0];
			if (Alignment == 0 || Alignment == 1 || Alignment == 2) // Align Center
			{
				Y_start = buf_y + H_Len - H_Size - (H_Len - row_num * H_Size) / 2;
			}
			else if (Alignment == 3 || Alignment == 4 || Alignment == 5) // Align up
			{
				Y_start = buf_y + H_Len - H_Size;
			}
			else if (Alignment == 6 || Alignment == 7 || Alignment == 8) // Align down
			{
				Y_start = buf_y + H_Len - (H_Len - row_num * H_Size) - H_Size;
			}
		}
		else if (Screen_DIR == 3)
		{
			if (Alignment == 0 || Alignment == 3 || Alignment == 6)
				Y_start = buf_y + W_Len;
			else if (Alignment == 1 || Alignment == 4 ||Alignment == 7)
				Y_start = buf_y + W_Len - (W_Len - row_w[0]) / 2;
			else if (Alignment == 2 || Alignment == 5 || Alignment == 8)
				Y_start = buf_y + row_w[0] - 1;

			if (Alignment == 0 || Alignment == 1 ||Alignment == 2) // Align  Center
			{
				X_start = buf_x + (H_Len - row_num * H_Size) / 2;
			}
			else if (Alignment == 3 || Alignment == 4 ||Alignment == 5) // Align  Up
			{
				X_start = buf_x;
			}
			else if (Alignment == 6 || Alignment == 7 ||Alignment == 8) // Align  Down
			{
				X_start = buf_x + H_Len - row_num * H_Size; // Xe - row_num * H_Size;
			}
		}
	}

	LT_ReadFlash_UI(Ascii_w, FlashAddr + 9, 95);
	LT_ReadFlash_UI(&gray, FlashAddr + 8, 1);

	i = 0;
	row = 0;
	x_des = X_start;
	y_des = Y_start;

	if (encode == 0 || encode == 1 || encode == 2 || encode == 4) // ASCII GB2312 GBK BIG5
	{
		if (encode == 0)		//GB2312
		{
			scode = 0xa1;
			ecode = 0x00;
		}
		else if (encode == 1)	//GBK
		{
			scode = 0x81;
			ecode = 0x40;
		}
		else if (encode == 2)	//BIG5
		{
			scode = 0xa1;
			ecode = 0x40;
		}
		else if (encode == 4)	//ASCII
		{
			scode = 0xff;
			ecode = 0xff;
		}

		while (1) // Automatic exit when meeting the end-of-transmission
		{
			if (c[i] < 128 && c[i] > 0x00)
				disp_w = Ascii_w[c[i] - 0x20] + dis_x + 2;
			else if (c[i] >= scode && c[i + 1] >= ecode && c[i] != 0xFF)
				disp_w = W_Size + dis_x;

			if (len_disp + disp_w > W_Len || c[i] == 0x0a)
			{
				row++;
				len_disp = 0;
				offset_disp += H_Size;

				if (offset_disp + H_Size > H_Len)
					break;

				if (Screen_DIR == 0)
				{
					if (Alignment == 0  || Alignment == 3 || Alignment == 6 )
						x_des = buf_x;
					else if (Alignment == 1 || Alignment == 4 || Alignment == 7)
						x_des = buf_x + (W_Len - row_w[row]) / 2;
					else if (Alignment == 2 || Alignment == 5 || Alignment == 8)
						x_des = buf_x + (W_Len - row_w[row]);

					y_des = Y_start + offset_disp;
				}
				else if (Screen_DIR == 1)
				{
					if (Alignment == 0  || Alignment == 3 || Alignment == 6 )
						y_des = buf_y;
					else if (Alignment == 1 || Alignment == 4 || Alignment == 7)
						y_des = buf_y + (W_Len - row_w[row]) / 2;
					else if (Alignment == 2 || Alignment == 5 || Alignment == 8)
						y_des = buf_y + (W_Len - row_w[row]);

					x_des = X_start - offset_disp;
				}
				else if (Screen_DIR == 2)
				{
					if (Alignment == 0  || Alignment == 3 || Alignment == 6 )
						x_des = buf_x + W_Len;
					else if (Alignment == 1 || Alignment == 4 || Alignment == 7)
						x_des = buf_x + W_Len - (W_Len - row_w[row]) / 2;
					else if (Alignment == 2 || Alignment == 5 || Alignment == 8)
						x_des = buf_x + row_w[row];

					y_des = Y_start - offset_disp;
				}
				else if (Screen_DIR == 3)
				{
					if (Alignment == 0  || Alignment == 3 || Alignment == 6 )
						y_des = buf_y + W_Len;
					else if (Alignment == 1 || Alignment == 4 || Alignment == 7)
						y_des = buf_y + W_Len - (W_Len - row_w[row]) / 2;
					else if (Alignment == 2 || Alignment == 5 || Alignment == 8)
						y_des = buf_y + row_w[row] - 1;

					x_des = X_start + offset_disp;
				}
			}
			if (c[i] < 128 && c[i] > 0x00)
			{
				 LT268_GrayScaleFont_dislay_BUFF(4, FlashAddr, W_Size, H_Size, gray,
				 									FontColor, BackColor, enbackcolor, Ascii_w[c[i] - 0x20] + dis_x + 2, &c[i],
				 									x_des, y_des, buf_w, buf);
				if (Screen_DIR == 0)
					x_des += (Ascii_w[c[i] - 0x20] + dis_x + 2);
				else if (Screen_DIR == 1)
					y_des += (Ascii_w[c[i] - 0x20] + dis_x + 2);
				else if (Screen_DIR == 2)
					x_des -= (Ascii_w[c[i] - 0x20] + dis_x + 2);
				else if (Screen_DIR == 3)
					y_des -= (Ascii_w[c[i] - 0x20] + dis_x + 2);

				len_disp += (Ascii_w[c[i] - 0x20] + dis_x + 2);
				i++;
				if (i >= len_max)
					break;
			}
			else if (c[i] >= scode && c[i + 1] >= ecode && c[i] != 0xFF)
			{
				LT268_GrayScaleFont_dislay_BUFF(encode, FlashAddr, W_Size, H_Size, gray,
															FontColor, BackColor, enbackcolor, W_Size + dis_x, &c[i],
															x_des, y_des, buf_w, buf);

				if (Screen_DIR == 0)
					x_des += (W_Size + dis_x);
				else if (Screen_DIR == 1)
					y_des += (W_Size + dis_x);
				else if (Screen_DIR == 2)
					x_des -= (W_Size + dis_x);
				else if (Screen_DIR == 3)
					y_des -= (W_Size + dis_x);
				len_disp += (W_Size + dis_x);
				i += 2;
				if (i >= len_max)
					break;
			}
			if (i >= len_max)
				break;
		}
	}
	else if (encode == 3 || encode == 6) // unicode
	{
		font_byte = (W_Size * gray_bit + 7) / 8 * H_Size;
		LT_ReadFlash_UI(buff_code, FlashAddr + 4, 4);
		scode = buff_code[0] + (buff_code[1] << 8);
		ecode = buff_code[2] + (buff_code[3] << 8);

		while (1) // Automatic exit when meeting the end-of-transmission
		{
			unicode = (c[i] << 8) + c[i + 1];

			if (unicode < 128 && unicode > 0x00)
				disp_w = Ascii_w[unicode- 0x20]  + dis_x + 2;
			else if (unicode >= scode && unicode <= ecode)
			{
				if (encode == 3)
					disp_w = W_Size + dis_x;
				else if (encode == 6)
				{
					LT_ReadFlash_UI(&unicode_w, FlashAddr + 104 + 95 * font_byte + (unicode - scode) * (font_byte + 1), 1);
					disp_w = unicode_w + dis_x;
				}
			}
			if (len_disp + disp_w > W_Len || unicode == 0x0a)
			{
				row++;
				len_disp = 0;
				offset_disp += H_Size;

				if (offset_disp + H_Size > H_Len)
					break;

				if (Screen_DIR == 0)
				{
					if (Alignment == 0  || Alignment == 3 || Alignment == 6 )
						x_des = buf_x;
					else if (Alignment == 1 || Alignment == 4 || Alignment == 7)
						x_des = buf_x + (W_Len - row_w[row]) / 2;
					else if (Alignment == 2 || Alignment == 5 || Alignment == 8)
						x_des = buf_x + (W_Len - row_w[row]);

					y_des = Y_start + offset_disp;
				}
				else if (Screen_DIR == 1)
				{
					if (Alignment == 0  || Alignment == 3 || Alignment == 6 )
						y_des = buf_y;
					else if (Alignment == 1 || Alignment == 4 || Alignment == 7)
						y_des = buf_y + (W_Len - row_w[row]) / 2;
					else if (Alignment == 2 || Alignment == 5 || Alignment == 8)
						y_des = buf_y + (W_Len - row_w[row]);

					x_des = X_start - offset_disp;
				}
				else if (Screen_DIR == 2)
				{
					if (Alignment == 0  || Alignment == 3 || Alignment == 6 )
						x_des = buf_x + W_Len;
					else if (Alignment == 1 || Alignment == 4 || Alignment == 7)
						x_des = buf_x + W_Len - (W_Len - row_w[row]) / 2;
					else if (Alignment == 2 || Alignment == 5 || Alignment == 8)
						x_des = buf_x + row_w[row];

					y_des = Y_start - offset_disp;
				}
				else if (Screen_DIR == 3)
				{
					if (Alignment == 0  || Alignment == 3 || Alignment == 6 )
						y_des = buf_y + W_Len;
					else if (Alignment == 1 || Alignment == 4 || Alignment == 7)
						y_des = buf_y + W_Len - (W_Len - row_w[row]) / 2;
					else if (Alignment == 2 || Alignment == 5 || Alignment == 8)
						y_des = buf_y + row_w[row] - 1;

					x_des = X_start + offset_disp;
				}
			}
			if (unicode< 128 && unicode > 0x00)
			{
				LT268_GrayScaleFont_dislay_BUFF(4, FlashAddr, W_Size, H_Size, gray,
				 									FontColor, BackColor, enbackcolor, Ascii_w[unicode - 0x20] + dis_x + 2, &c[i + 1],
				 									x_des, y_des, buf_w, buf);

				if (Screen_DIR == 0)
					x_des += (Ascii_w[unicode - 0x20] + dis_x + 2);
				else if (Screen_DIR == 1)
					y_des += (Ascii_w[unicode - 0x20] + dis_x + 2);
				else if (Screen_DIR == 2)
					x_des -= (Ascii_w[unicode - 0x20] + dis_x + 2);
				else if (Screen_DIR == 3)
					y_des -= (Ascii_w[unicode - 0x20] + dis_x + 2);
				len_disp += (Ascii_w[unicode - 0x20] + dis_x + 2);
				i+=2;
				if (i >= len_max)
					break;
			}
			else if (unicode >= scode && unicode <= ecode)
			{
				unicode -= scode;
				LT268_GrayScaleFont_dislay_BUFF(encode, FlashAddr, W_Size, H_Size, gray,
												FontColor, BackColor, enbackcolor, disp_w,(uint8_t *)(&unicode),
												x_des, y_des, buf_w, buf);
				if (Screen_DIR == 0)
					x_des += disp_w;
				else if (Screen_DIR == 1)
					y_des += disp_w;
				else if (Screen_DIR == 2)
					x_des -= disp_w;
				else if (Screen_DIR == 3)
					y_des -= disp_w;
				len_disp += disp_w;
				i += 2;
				if (i >= len_max)
					break;
			}
			if (i >= len_max)
				break;
		}
	}
	else if (encode == 9) // str
	{
		font_byte = (W_Size * gray_bit + 7) / 8 * H_Size;

		LT_ReadFlash_UI(buff_code, FlashAddr + 4, 2);
		str_num = buff_code[0] + (buff_code[1] << 8);

		LT_ReadFlash_UI(DMA_rxbuf1, FlashAddr + 9, str_num * 2);

		while (1) // Automatic exit when meeting the end-of-transmission
		{
			if (c[i] < 128 && c[i] > 0x00)
				unicode = c[i];
			else
				unicode = (c[i] << 8) + c[i + 1];

			for(k = 0; k < str_num; k++)
			{
				if (unicode == (DMA_rxbuf1[k*2] + (DMA_rxbuf1[k*2 + 1] <<  8)))
				{
					LT_ReadFlash_UI(&unicode_w, FlashAddr + 9 + str_num * 2 + k * (font_byte + 1) , 1);
					if (unicode< 128 && unicode > 0x00)
						disp_w = unicode_w + dis_x + 2;
					else
						disp_w = unicode_w + dis_x;
					break;
				}
			}

			if (len_disp + disp_w > W_Len || unicode == 0x0a)
			{
				row++;
				len_disp = 0;
				offset_disp += H_Size;

				if (offset_disp + H_Size > H_Len)
					break;

				if (Screen_DIR == 0)
				{
					if (Alignment == 0  || Alignment == 3 || Alignment == 6 )
						x_des = buf_x;
					else if (Alignment == 1 || Alignment == 4 || Alignment == 7)
						x_des = buf_x + (W_Len - row_w[row]) / 2;
					else if (Alignment == 2 || Alignment == 5 || Alignment == 8)
						x_des = buf_x + (W_Len - row_w[row]);

					y_des = Y_start + offset_disp;
				}
				else if (Screen_DIR == 1)
				{
					if (Alignment == 0  || Alignment == 3 || Alignment == 6 )
						y_des = buf_y;
					else if (Alignment == 1 || Alignment == 4 || Alignment == 7)
						y_des = buf_y + (W_Len - row_w[row]) / 2;
					else if (Alignment == 2 || Alignment == 5 || Alignment == 8)
						y_des = buf_y + (W_Len - row_w[row]);

					x_des = X_start - offset_disp;
				}
				else if (Screen_DIR == 2)
				{
					if (Alignment == 0  || Alignment == 3 || Alignment == 6 )
						x_des = buf_x + W_Len;
					else if (Alignment == 1 || Alignment == 4 || Alignment == 7)
						x_des = buf_x + W_Len - (W_Len - row_w[row]) / 2;
					else if (Alignment == 2 || Alignment == 5 || Alignment == 8)
						x_des = buf_x + row_w[row];

					y_des = Y_start - offset_disp;
				}
				else if (Screen_DIR == 3)
				{
					if (Alignment == 0  || Alignment == 3 || Alignment == 6 )
						y_des = buf_y + W_Len;
					else if (Alignment == 1 || Alignment == 4 || Alignment == 7)
						y_des = buf_y + W_Len - (W_Len - row_w[row]) / 2;
					else if (Alignment == 2 || Alignment == 5 || Alignment == 8)
						y_des = buf_y + row_w[row] - 1;

					x_des = X_start + offset_disp;
				}
			}
			if (unicode != 0x0A)
			{
				unicode = k;
				LT268_GrayScaleFont_dislay_BUFF(encode, FlashAddr + 9 + str_num * 2, W_Size, H_Size, gray,
												FontColor, BackColor, enbackcolor, disp_w,(uint8_t *)(&unicode),
												x_des, y_des, buf_w, buf);

				if (Screen_DIR == 0)
					x_des += disp_w;
				else if (Screen_DIR == 1)
					y_des += disp_w;
				else if (Screen_DIR == 2)
					x_des -= disp_w;
				else if (Screen_DIR == 3)
					y_des -= disp_w;
				len_disp += disp_w;

				if (unicode< 128 && unicode > 0x00)
					i++;
				else
					i +=2;

				if (i >= len_max)
					break;
			}
			if (i >= len_max)
				break;
		}
	}
	return 0;
}

/*******************************************************************************
 * Function Name : LT_Print_zk_Font_Scroll
 * Description   : txt scroll.
 * Input         :
 * Output        : None
 * Return        : None
 ********************************************************************/
uint16_t LT_Print_zk_Font_Scroll(
	uint16_t encode // encoding type     0:GB2312  1:GBK  2:BIG5  3:UNICODE  4:ASCII
	,
	uint32_t FlashAddr // Font source address(exSpiFlash)
	,
	uint32_t ShowAddr // Displays the address of the layer
	,
	uint16_t width // Display the width of the layer
	,
	uint8_t W_Size //  font width
	,
	uint8_t H_Size // font height
	,
	uint8_t Alignment // Alignment
	,
	uint32_t FontColor // The foreground color of the font
	,
	uint32_t BackColor // The background color of the font
	,
	uint8_t enbackcolor // Background color enable, 0:disable  1:enable
	,
	uint8_t mix // mix mode, 0:with fullscreen interface   1:with specific pictures(Text box needs to be fully included)
	,
	_PICINFO mixpic // mix picture info
	,
	uint16_t Xs // Text box start x position
	,
	uint16_t Ys // Text box start Y position
	,
	uint16_t Xe // Text box end x position
	,
	uint16_t Ye // Text box end y position
	,
	uint8_t dis_x // The interval between two adjacent fonts on the x-axis
	,
	uint8_t dis_y // The interval between two adjacent fonts on the y-axis
	,
	uint8_t *c // Address of text
	,
	uint16_t len_max // max lenght of text
	,
	uint8_t num // Scroll_num
	,
	uint16_t x_off // x offset
)
{
	uint16_t temp = 0, temp_H = 0, temp_L = 0;
	uint32_t i = 0;
	uint16_t X_start = 0, Y_start = 0;
	uint8_t gray, gray_bit;
	uint16_t disp_w = 0, disp_i = 0;
	uint16_t temp_w;
	uint16_t box_w = Xe - Xs + 1, box_h = Ye - Ys + 1;
	uint16_t buf_w = 0, buf_h = Ye - Ys + 1;

	uint16_t x_src = 0, y_src = 0, x_des = 0, y_des = 0, w_real = 0, h_real = 0;
	uint16_t scode,ecode;
	uint8_t unicode_w;
	uint16_t font_byte; // bytes of a single font

	if (Screen_DIR == 0 || Screen_DIR == 2)
	{
		w_real = Xe - Xs + 1;
		h_real = Ye - Ys + 1;
	}
	else if (Screen_DIR == 1 || Screen_DIR == 3)
	{
		w_real = Ye - Ys + 1;
		h_real = Xe - Xs + 1;
	}

	LT_ReadFlash_UI(Ascii_w, FlashAddr + 9, 95);
	LT_ReadFlash_UI(&gray, FlashAddr + 8, 1);
	
	if (gray == 0)
		gray_bit = 1;
	else if (gray == 1)
		gray_bit = 2;
	else if (gray == 2)
		gray_bit = 4;

	i = 0;
	if (encode == 4) // ASCII
	{
		while (1)
		{
			if (c[i] < 128 && c[i] > 0x00)
			{
				buf_w += (Ascii_w[c[i] - 0x20] + dis_x + 2);
				i++;
			}
			else
				break;
		}
	}
	else if (encode == 0)
	{
		while (1)
		{
			if (c[i] < 128 && c[i] > 0x00)
			{
				buf_w += Ascii_w[c[i] - 0x20] + dis_x + 2;
				i++;
			}
			else if (c[i] >= 0xa1 && c[i] != 0xFF)
			{
				buf_w += W_Size + dis_x;
				i += 2;
			}
			else
				break;
		}
	}
	else if (encode == 1)
	{
		while (1)
		{
			if (c[i] < 128 && c[i] > 0x00)
			{
				buf_w += (Ascii_w[c[i] - 0x20] + dis_x + 2);
				i++;
			}
			else if (c[i] >= 0x81 && c[i + 1] >= 0x40 && c[i] != 0xFF)
			{
				buf_w += W_Size + dis_x;
				i += 2;
			}
			else
				break;
		}
	}
	else if (encode == 2)
	{
		while (1)
		{
			if (c[i] < 128 && c[i] > 0x00)
			{
				buf_w += (Ascii_w[c[i] - 0x20] + dis_x + 2);
				i++;
			}
			else if (c[i] >= 0xa1 && c[i + 1] >= 0x40)
			{
				buf_w += W_Size + dis_x;
				i += 2;
			}
			else
				break;
		}
	}
	else if (encode == 3)
	{
		uint16_t unicode = 0, unicode_temp = 0;
		uint16_t start_code = 0, end_code = 0;
		uint8_t buff_code[4];

		LT_ReadFlash_UI(buff_code, FlashAddr + 4, 4);
		start_code = buff_code[0] + (buff_code[1] << 8);
		end_code = buff_code[2] + (buff_code[3] << 8);

		while (1)
		{
			unicode = (c[i] << 8) + c[i + 1];
			if (unicode == 0x0000)
				break;
			else if (unicode < 128 && unicode > 0x00)
			{
				buf_w += (Ascii_w[unicode - 0x20] + dis_x + 2);
				i += 2;
			}
			else if (unicode >= start_code && unicode <= end_code)
			{
				buf_w += W_Size + dis_x;
				i += 2;
			}
			else
				break;
		}
	}
	else if (encode == 6)
	{
		uint16_t unicode = 0, unicode_temp = 0;
		uint16_t start_code = 0, end_code = 0;
		uint8_t buff_code[4];

		font_byte = (W_Size * gray_bit + 7) / 8 * H_Size;

		LT_ReadFlash_UI(buff_code, FlashAddr + 4, 4);
		start_code = buff_code[0] + (buff_code[1] << 8);
		end_code = buff_code[2] + (buff_code[3] << 8);

		while (1)
		{
			unicode = (c[i] << 8) + c[i + 1];

			if (unicode == 0x0000)
				break;
			if (unicode < 128 && unicode > 0x00)
			{
				buf_w += (Ascii_w[unicode - 0x20] + dis_x + 2);
				i += 2;
			}
			else if (unicode >= start_code && unicode <= end_code)
			{
				LT_ReadFlash_UI(&unicode_w, FlashAddr + 104 + 95 * font_byte + (unicode - start_code) * (font_byte + 1), 1);
				buf_w += (unicode_w + dis_x);
				i += 2;
			}
			else
				break;
		}
	}
	len_max = i;

	if (buf_w > w_real)
	{
		buf_w = buf_w + gScroll_Info[num].gap;

		if (Screen_DIR == 2)
		{
			if (gScroll_Info[num].flag == 2)
			{
				gScroll_Info[num].cnt = buf_w - gScroll_Info[num].w;
				x_off = gScroll_Info[num].cnt;
			}
			X_start = buf_w - 1;
		}
		else if (Screen_DIR == 3)
		{
			if (gScroll_Info[num].flag == 2)
			{
				gScroll_Info[num].cnt = buf_w - gScroll_Info[num].h;
				x_off = gScroll_Info[num].cnt;
			}
			Y_start = buf_w - 1;;
		}
		gScroll_Info[num].flag = 1;
	}
	else if (buf_w + gScroll_Info[num].gap > w_real)
	{
		buf_w = w_real + gScroll_Info[num].gap;

		 if (Screen_DIR == 2)
		{
			if (gScroll_Info[num].flag == 2)
			{
				gScroll_Info[num].cnt = buf_w - gScroll_Info[num].w;
				x_off = gScroll_Info[num].cnt;
			}
			X_start = buf_w - 1;
		}
		else if (Screen_DIR == 3)
		{
			if (gScroll_Info[num].flag == 2)
			{
				gScroll_Info[num].cnt = buf_w - gScroll_Info[num].h;
				x_off = gScroll_Info[num].cnt;
			}
			Y_start = buf_w - 1;;
		}
		gScroll_Info[num].flag = 1;
	}
	else
	{
		if (gScroll_Info[num].scroll_en)
		{
			buf_w = w_real + gScroll_Info[num].gap;

			if (Screen_DIR == 2)
			{
				if (gScroll_Info[num].flag == 2)
				{
					gScroll_Info[num].cnt = buf_w - gScroll_Info[num].w;
					x_off = gScroll_Info[num].cnt;
				}
				X_start = buf_w - 1;
			}
			else if (Screen_DIR == 3)
			{
				if (gScroll_Info[num].flag == 2)
				{
					gScroll_Info[num].cnt = buf_w - gScroll_Info[num].h;
					x_off = gScroll_Info[num].cnt;
				}
				Y_start = buf_w - 1;;
			}
			gScroll_Info[num].flag = 1;
		}
		else
		{
			if (Screen_DIR == 0)
			{
				if (Alignment == 0)
					X_start = 0;
				else if (Alignment == 1)
					X_start = (w_real - buf_w) / 2;
				else if (Alignment == 2)
					X_start = w_real - buf_w;
			}
			else if (Screen_DIR == 1)
			{
				if (Alignment == 0)
					Y_start = 0;
				else if (Alignment == 1)
					Y_start = (w_real - buf_w) / 2;
				else if (Alignment == 2)
					Y_start = w_real - buf_w;
			}
			else if (Screen_DIR == 2)
			{
				if (Alignment == 0)
					X_start = w_real;
				else if (Alignment == 1)
					X_start = w_real - (w_real - buf_w) / 2;
				else if (Alignment == 2)
					X_start = buf_w;
			}
			else if (Screen_DIR == 3)
			{
				if (Alignment == 0)
					Y_start = w_real;
				else if (Alignment == 1)
					Y_start = w_real - (w_real - buf_w) / 2;
				else if (Alignment == 2)
					Y_start = buf_w;
			}
			buf_w = w_real;
			gScroll_Info[num].flag = 0;
		}
	}

	if (Screen_DIR == 0)
		Y_start = (h_real - H_Size)/2;
	else if (Screen_DIR == 1)
		X_start = (h_real - H_Size)/2;
	else if (Screen_DIR == 2)
		Y_start = (h_real - H_Size)/2;
	else if (Screen_DIR == 3)
		X_start = (h_real - H_Size)/2;

	if (buf_w * h_real * 2 > MAX_PixelSize)
		return 1;

	gScroll_Info[num].buf_w = buf_w;

	if ((x_off + w_real) <= buf_w)
	{
		if (enbackcolor)
		{
			if(Screen_DIR == 0 || Screen_DIR == 2)
			{
				LT268_BG_to_Pure(x_off, 0, buf_w, m_PngData,
								 box_w, box_h, BackColor);
			}
			else if(Screen_DIR == 1 || Screen_DIR == 3)
			{
				LT268_BG_to_Pure(0, 0, box_w, m_PngData,
								 box_w, buf_w, BackColor);
			}
		}
		else
		{
			if (mix == 0)
			{
				if(Screen_DIR == 0 || Screen_DIR == 2)
				{
					LT268_BG_to_buffer(x_off, 0, buf_w, m_PngData,
										Xs, Ys,box_w, box_h);
				}
				else if(Screen_DIR == 1 || Screen_DIR == 3)
				{
					LT268_BG_to_buffer(0, x_off, box_w, m_PngData,
										Xs, Ys,box_w, box_h);
				}
			}
			else
			{
				if (mixpic.flag == 0x10)
				{
					if(Screen_DIR == 0 || Screen_DIR == 2)
					{
						LT268_BG_to_Pure(x_off, 0, buf_w, m_PngData,
										box_w, box_h, mixpic.len);
					}
					else if(Screen_DIR == 1 || Screen_DIR == 3)
					{
						LT268_BG_to_Pure(0, x_off, box_w, m_PngData,
										box_w, box_h, mixpic.len);
					}
				}
				else
				{
					if(Screen_DIR == 0 || Screen_DIR == 2)
					{
						if (mixpic.flag != 0)
							LT268_BG_to_buffer(x_off, 0, buf_w, m_PngData,
												Xs, Ys, box_w, box_h);

						LT268_pic_to_buffer(x_off, 0, buf_w, m_PngData, Xs - mixpic.x, Ys - mixpic.y, mixpic.w, mixpic.addr, box_w, box_h, mixpic.flag);

					}
					else if(Screen_DIR == 1 || Screen_DIR == 3)
					{
						if (mixpic.flag != 0)
							LT268_BG_to_buffer(0, x_off, box_w, m_PngData,
												Xs, Ys, box_w, box_h);

						LT268_pic_to_buffer(0, x_off, box_w, m_PngData, Xs - mixpic.x, Ys - mixpic.y, mixpic.w, mixpic.addr, box_w, box_h, mixpic.flag);
					}
				}
			}
		}
	}
	else
	{
		if (enbackcolor)
		{
			if(Screen_DIR == 0 || Screen_DIR == 2)
			{
				LT268_BG_to_Pure(0, 0, buf_w, m_PngData,
								buf_w, box_h, BackColor);
			}
			else if(Screen_DIR == 1 || Screen_DIR == 3)
			{
				LT268_BG_to_Pure(0, 0, box_w, m_PngData,
								box_w, buf_w, BackColor);
			}
		}
		else
		{
			if (mix == 0)
			{
				if(Screen_DIR == 0 || Screen_DIR == 2)
				{
					LT268_BG_to_buffer(x_off, 0, buf_w, m_PngData,
										Xs, Ys, buf_w - x_off, box_h);
					LT268_BG_to_buffer(0, 0, buf_w, m_PngData,
										Xs + buf_w - x_off, Ys, box_w - (buf_w - x_off), box_h);
				}
				else if(Screen_DIR == 1 || Screen_DIR == 3)
				{
					LT268_BG_to_buffer(0, x_off, box_w, m_PngData,
										Xs, Ys, box_w, buf_w - x_off);
					LT268_BG_to_buffer(0, 0, box_w, m_PngData,
										Xs, Ys + buf_w - x_off, box_w, box_h - (buf_w - x_off));
				}
			}
			else
			{
				if (mixpic.flag == 0x10)
				{
					if(Screen_DIR == 0 || Screen_DIR == 2)
					{

						LT268_BG_to_Pure(0, 0, buf_w, m_PngData,
										buf_w, box_h, mixpic.len);
					}
					else if(Screen_DIR == 1 || Screen_DIR == 3)
					{
						LT268_BG_to_Pure(0, 0, box_w, m_PngData,
										box_w, buf_w, mixpic.len);
					}
				}
				else
				{
					if(Screen_DIR == 0 || Screen_DIR == 2)
					{
						if (mixpic.flag != 0)
						{
							LT268_BG_to_buffer(x_off, 0, buf_w, m_PngData,
												Xs, Ys, buf_w - x_off, box_h);
							LT268_BG_to_buffer(0, 0, buf_w, m_PngData,
												Xs + buf_w - x_off, Ys, box_w - (buf_w - x_off), box_h);
						}
						LT268_pic_to_buffer(x_off, 0, buf_w, m_PngData,
											Xs - mixpic.x, Ys - mixpic.y, mixpic.w, mixpic.addr,
											buf_w - x_off, box_h, mixpic.flag);
						LT268_pic_to_buffer(0, 0, buf_w, m_PngData,
											Xs - mixpic.x + buf_w - x_off, Ys - mixpic.y, mixpic.w, mixpic.addr,
											box_w - (buf_w - x_off), box_h, mixpic.flag);
					}
					else if(Screen_DIR == 1 || Screen_DIR == 3)
					{
						if (mixpic.flag != 0)
						{
							LT268_BG_to_buffer(0, x_off, box_w, m_PngData,
												Xs, Ys, box_w, buf_w - x_off);
							LT268_BG_to_buffer(0, 0, box_w, m_PngData,
												Xs, Ys + buf_w - x_off, box_w, box_h - (buf_w - x_off));
						}
						LT268_pic_to_buffer(0, x_off, box_w, m_PngData,
											Xs - mixpic.x, Ys - mixpic.y, mixpic.w, mixpic.addr,
											box_w, buf_w - x_off, mixpic.flag);
						LT268_pic_to_buffer(0, 0, box_w, m_PngData,
											Xs - mixpic.x, Ys - mixpic.y + buf_w - x_off, mixpic.w, mixpic.addr,
											box_w, box_h - (buf_w - x_off), mixpic.flag);
					}
				}
			}
		}
	}

	i = 0;
	if (Screen_DIR == 1 || Screen_DIR == 3)
		buf_w = box_w;
	if (encode == 0 || encode == 1 || encode == 2 || encode == 4) // ASCII GB2312 GBK BIG5
	{
		if (encode == 0)		//GB2312
		{
			scode = 0xa1;
			ecode = 0x00;
		}
		else if (encode == 1)	//GBK
		{
			scode = 0x81;
			ecode = 0x40;
		}
		else if (encode == 2)	//BIG5
		{
			scode = 0xa1;
			ecode = 0x40;
		}
		else if (encode == 4)	//ASCII
		{
			scode = 0xff;
			ecode = 0xff;
		}

		while (1) // Automatic exit when meeting the end-of-transmission
		{
			if (c[i] < 128 && c[i] > 0x00)
			{
				 LT268_GrayScaleFont_dislay_BUFF(4, FlashAddr, W_Size, H_Size, gray,
				 									FontColor, BackColor, enbackcolor, Ascii_w[c[i] - 0x20] + dis_x + 2, &c[i],
				 									X_start, Y_start, buf_w, m_PngData);
				 if (Screen_DIR == 0)
					X_start += (Ascii_w[c[i] - 0x20] + dis_x + 2);
				else if (Screen_DIR == 1)
					Y_start += (Ascii_w[c[i] - 0x20] + dis_x + 2);
				else if (Screen_DIR == 2)
					X_start -= (Ascii_w[c[i] - 0x20] + dis_x + 2);
				else if (Screen_DIR == 3)
					Y_start -= (Ascii_w[c[i] - 0x20] + dis_x + 2);

				i++;
				if (i >= len_max)
					break;
			}
			else if (c[i] >= scode && c[i + 1] >= ecode && c[i] != 0xFF)
			{
				LT268_GrayScaleFont_dislay_BUFF(encode, FlashAddr, W_Size, H_Size, gray,
															FontColor, BackColor, enbackcolor, W_Size + dis_x, &c[i],
															X_start, Y_start, buf_w, m_PngData);

				if (Screen_DIR == 0)
					X_start += (W_Size + dis_x);
				else if (Screen_DIR == 1)
					Y_start += (W_Size + dis_x);
				else if (Screen_DIR == 2)
					X_start -= (W_Size + dis_x);
				else if (Screen_DIR == 3)
					Y_start -= (W_Size + dis_x);

				i += 2;
				if (i >= len_max)
					break;
			}
			if (i >= len_max)
				break;
		}
	}
	else if (encode == 3 || encode == 6) // unicode
	{
		uint16_t unicode = 0, unicode_temp = 0;
		uint16_t start_code = 0, end_code = 0;
		uint8_t buff_code[4];

		font_byte = (W_Size * gray_bit + 7) / 8 * H_Size;
		LT_ReadFlash_UI(buff_code, FlashAddr + 4, 4);
		scode = buff_code[0] + (buff_code[1] << 8);
		ecode = buff_code[2] + (buff_code[3] << 8);

		while (1) // Automatic exit when meeting the end-of-transmission
		{
			unicode = (c[i] << 8) + c[i + 1];

			if (unicode < 128 && unicode > 0x00)
				disp_w = Ascii_w[unicode- 0x20]  + dis_x + 2;
			else if (unicode >= scode && unicode <= ecode)
			{
				if (encode == 3)
					disp_w = W_Size + dis_x;
				else if (encode == 6)
				{
					LT_ReadFlash_UI(&unicode_w, FlashAddr + 104 + 95 * font_byte + (unicode - scode) * (font_byte + 1), 1);
					disp_w = unicode_w + dis_x;
				}
			}

			if (unicode< 128 && unicode > 0x00)
			{
				LT268_GrayScaleFont_dislay_BUFF(4, FlashAddr, W_Size, H_Size, gray,
												FontColor, BackColor, enbackcolor, Ascii_w[unicode - 0x20] + dis_x + 2, &c[i+1],
												X_start, Y_start, buf_w, m_PngData);
				if (Screen_DIR == 0)
					X_start += (Ascii_w[unicode - 0x20] + dis_x + 2);
				else if (Screen_DIR == 1)
					Y_start += (Ascii_w[unicode - 0x20] + dis_x + 2);
				else if (Screen_DIR == 2)
					X_start -= (Ascii_w[unicode - 0x20] + dis_x + 2);
				else if (Screen_DIR == 3)
					Y_start -= (Ascii_w[unicode - 0x20] + dis_x + 2);
				i+=2;
				if (i >= len_max)
					break;
			}
			else if (unicode >= scode && unicode <= ecode)
			{
				unicode -= scode;

				LT268_GrayScaleFont_dislay_BUFF(encode, FlashAddr, W_Size, H_Size, gray,
												FontColor, BackColor, enbackcolor, disp_w, (uint8_t *)(&unicode),
												X_start, Y_start, buf_w, m_PngData);

				if (Screen_DIR == 0)
					X_start += disp_w;
				else if (Screen_DIR == 1)
					Y_start += disp_w;
				else if (Screen_DIR == 2)
					X_start -= disp_w;
				else if (Screen_DIR == 3)
					Y_start -= disp_w;

				i += 2;
				if (i >= len_max)
					break;
			}
			if (i >= len_max)
				break;
		}
	}
	return 0;
}

/***********************************************************************************
 * Function Name : BackLight_control
 * Description   : Automatically adjust backlight.
 * Input         : None
 * Output        : None
 * Return        : None
 ************************************************************************************/
void BackLight_control(void)
{
	if (Backlight_flag == 1) // backlight is working and waiting to enter standby mode
	{
		if(Backlight_touch)
		{
			if(First_press == 1)
			{
				gTpInfo.sta = 0;
				Backlight_count = 0;
			}
			else
			{
				gTpInfo.sta = 0;
				Backlight_count = 0;
				Backlight_touch = 0;      // enable touch function     
			}
		}
		
		if (gTpInfo.sta == 1) // clear count
		{
			Backlight_count = 0;
			Backlight_touch = 0;
		}
		else if (Backlight_count >= ((var[VAR_BLDURATION * 2] << 8) + var[VAR_BLDURATION * 2 + 1 ]) * 100) 
		{
			LT_BacklightSet(gDutyBuf[var[VAR_BLSLEEP * 2 + 1]]);  // sleep
			Backlight_count = 0;
			Backlight_flag = 0;
		}
	}
	else if (Backlight_flag == 0 && gTpInfo.sta == 1) // backlight wake up
	{
		if (buzzer) touch_buzzer();
		gTpInfo.sta = 0;
		Backlight_touch = 1;
		Backlight_count = 0;
		Backlight_flag = 1;
		LT_BacklightSet(gDutyBuf[var[VAR_BL * 2 + 1]]);
	}
}

// 切换到另一套UI，并重刷当前页
void LT_LCD_screen_dir(uint8_t dir)
{
//	LT_BacklightClose();	// backlight close

	if (dir > 3) dir = 3;
	lt_ui_change = dir;

#if 1
	//---screen direction----------------------------------
	if(dir!=lt_ui_change)
	{
		/*screen init*/
		// ILI9488: reference : 0=0x48 1=0x28  2=0x88 3=0xf8
		TFT_CommandWrite(0x36);
		if(dir==0)		TFT_DataWrite(0x48); // 0°
		else if(dir==1)	TFT_DataWrite(0x28); // 90°
		else if(dir==2)	TFT_DataWrite(0x88); // 180°
		else if(dir==3)	TFT_DataWrite(0xf8); // 270°
	}
#endif

#if 1
	//屏分辨率修改
	uint16_t w = LCD_XSIZE_TFT, h = LCD_YSIZE_TFT;
	if (dir == 0 || dir == 2)
	{
		LCD_XSIZE_TFT = w;
		LCD_YSIZE_TFT = h;
	}
	else if (dir == 1 || dir == 3)
	{
		LCD_XSIZE_TFT = h;
		LCD_YSIZE_TFT = w;
	}
#endif

	//---ui show-------------------------------------------------
	Address_Index();
	if(GBKioKb_flag == 1 || DioKb_flag == 1 || AioKb_flag == 1)
	{
		if (Pop_up_flag == 0)
			Display_page(pic_id_temp);
		else if (Pop_up_flag == 1)
		{
			Pop_up_flag = 0;
			pic_id = (var[VAR_PAGE*2]<<8) + var[VAR_PAGE*2+1];
			Display_page(pic_id);
			Pop_up_flag = 1;
			Display_pop_up(Pop_up_id, Pop_up_x, Pop_up_y);
		}
	}
	else if(Pop_up_flag)	    // 弹窗
	{
		Pop_up_flag = 0;
		pic_id = (var[VAR_PAGE*2]<<8) + var[VAR_PAGE*2+1];
		Display_page(pic_id);
		Pop_up_flag = 1;
		Display_pop_up(Pop_up_id,Pop_up_x,Pop_up_y);
	}
	else
		Display_page(pic_id);
}

void LT_TP_dir_XY(void) //电容屏
{
#if 1
	uint16_t tempx=gTpInfo.x[0], tempy=gTpInfo.y[0];
	if(Screen_DIR==0)
	{
//		gTpInfo.x[0] = tempy;
//		gTpInfo.y[0] = LCD_YSIZE_TFT - tempx;
	}
	else if(Screen_DIR==1)
	{
		gTpInfo.x[0] = tempy;
		gTpInfo.y[0] = LCD_YSIZE_TFT - tempx;
	}
	else if(Screen_DIR==2)
	{
		gTpInfo.x[0] = LCD_XSIZE_TFT - tempx;
		gTpInfo.y[0] = LCD_YSIZE_TFT - tempy;
	}
	else if(Screen_DIR==3)
	{
		gTpInfo.x[0] = LCD_XSIZE_TFT - tempy;
		gTpInfo.y[0] = tempx;
	}
#endif
}

/* 唤醒源为IO口，但是由于设置sleep的函数在8K ROM 里，
   并且会让内部Flash进入低功耗，所以中断向量表此时不能用，
   故不打开IO对应的全局中断使能，防止程序在无法访问的地址
   卡死。

   EPORT0_5,EPORT0_6,EPORT0_7 都可以唤醒

 */

void Cache_Init(void);

//低功耗-模块关闭
#define close_rtc  0
#define close_other_ram  0
#define close_IO   0           //开启并根据实际情况配置eport来降低耗电
#define close_1P2  0
#define close_usb  0

void lt_mcu_low_power(void)
{
	//--唤醒源触发设置-------------------------------------------------------------------------

	//关闭屏背光，TFT进入休眠
	LT_BacklightClose();
	TFT_Enter_Sleep();

	//唤醒源
	// wake-up source: int0[0~7],other
	// CCM->WKUPC = 0x7FFFFFFF;
	// LTPrintf("CCM->WKUPC %#x  \r\n",CCM->WKUPC);

	/* 设置 EPORT上拉输入， 低电平中断 作为唤醒源 */
	PIN_EPORT0_5();
	PIN_EPORT0_6();
	PIN_EPORT0_7();

	eport_config_ts eport_init_config;
	eport_init_config.pin = EPORT_PIN_7;
	eport_init_config.mode = EPORT_INPUT;
	eport_init_config.pullup = EPORT_Pull_up;
	eport_init_config.int_type = EPORT_Level;
	eport_init_config.level = EPORT_Level_LOW;
	eport_init_config.int_enable = Disable;
	EPORT_Init(EPORT0, &eport_init_config);

	eport_init_config.pin = EPORT_PIN_6;
	eport_init_config.mode = EPORT_INPUT;
	eport_init_config.pullup = EPORT_Pull_up;
	eport_init_config.int_type = EPORT_Level;
	eport_init_config.level = EPORT_Level_LOW;
	eport_init_config.int_enable = Disable;
	EPORT_Init(EPORT0, &eport_init_config);

	eport_init_config.pin = EPORT_PIN_5;
	eport_init_config.mode = EPORT_INPUT;
	eport_init_config.pullup = EPORT_Pull_up;
	eport_init_config.int_type = EPORT_Level;
	eport_init_config.level = EPORT_Level_LOW;
	eport_init_config.int_enable = Enable;
	EPORT_Init(EPORT0, &eport_init_config);

	//关闭中断
	EIC_Cmd_Interrupt(EIC_IT_EPORT0, Disable); /* 关闭EPORT0的全局中断使能 */
//	EIC->IER = 0;							   // Disable All Interrupts
//	WDT->WCR = 0x0;

	//--低功耗设置----------------------------------------------------------------------------
	if (CLOCK_Sleep_Init(CLOCK_Sleep_Mode_3) == OK)
	{
		/* 进入低功耗前，关闭其他耗电模组 */
#if close_rtc
		/* 关闭RTC */
		RTC->PRKEYR = 0x5AA55AA5;

		Bit_Clear(RTC->PRCSR, 0x01);			 /* clear dir */
		for (; Bit_Read(RTC->PRCSR, 0x04) == 0;) /* wait CntUpdate_EN to 1 */
			asm("nop");

		RTC->PRCSR |= (19) << 3;
		RTC->PRT1R = 1;
		RTC->PRT2R = 0;
		for (; Bit_Read(RTC->PRCSR, 0x04) == 0;) /* wait CntUpdate_EN to 1 */
			asm("nop");

		// LTPrintf("%x \r\n", RTC->PRENR);
		for (; Bit_Read(RTC->PRENR, 0x400) == 0;) /* wait RTC_EN_Update_EN to 1 */
			asm("nop");
		RTC->PRENR &= ~(1 << 8);				  /* clear RTC_EN_DIR */
		RTC->PRENR &= ~0x01;					  /* disable RTC */
		for (; Bit_Read(RTC->PRENR, 0x400) == 0;) /* wait RTC_EN_Update_EN to 1 */
			asm("nop");
#endif

#if close_other_ram
		/* 关闭其他的sram*/
		CCM->MCU_RAM_PRIOCR = (CCM->MCU_RAM_PRIOCR & ~(0xC0000000)) | (0x01 << 30);
		CCM->MCU_RAM_PRIOCR = (CCM->MCU_RAM_PRIOCR & ~(0xC0000000)) | (0x02 << 30);
		CCM->MCU_RAM_PRIOCR = (CCM->MCU_RAM_PRIOCR & ~(0xC0000000)) | (0x03 << 30);

		CCM->MCU_RAM_PRIOCR |= (0x1F << 17); /* 隔离 display ram,cache ram,sysram1,sysram2,sysra3 */
		// DelayMS(5);
		CCM->MCU_RAM_PRIOCR |= (0x0F << 25); /* 关闭 display ram,cache ram,sysram1,sysram2,sysra3 */
//	 	LTPrintf("CCM->MCU_RAM_PRIOCR:%x\r\n",CCM->MCU_RAM_PRIOCR);
#endif

#if close_usb
		CLOCK->MSCR = ((CLOCK->MSCR & 0x3FFFFFFF) | 0x40000000);
		CLOCK->MSCR = ((CLOCK->MSCR & 0x3FFFFFFF) | 0x80000000);
		CLOCK->MSCR = ((CLOCK->MSCR & 0x3FFFFFFF) | 0xC0000000);
		CLOCK->MSCR &= ~CLOCK_MSCR_USB_MASK;
		USB->USBPHY_CTRL3 = 0x88;
		USB->USBPHY_CTRL2 = 0x80;
//		LTPrintf("CLOCK->MSCR:%x \r\n",CLOCK->MSCR);
//		LTPrintf("USBPHY_CTRL2:%x \r\n",USB->USBPHY_CTRL2);
//		LTPrintf("USBPHY_CTRL3:%x \r\n",USB->USBPHY_CTRL3);
#endif

#if close_1P2
		OPTION->VREFTCR = (OPTION->VREFTCR & (0x3F)) | (0x40);
		OPTION->VREFTCR = (OPTION->VREFTCR & (0x3F)) | (0x80);
		OPTION->VREFTCR = (OPTION->VREFTCR & (0x3F)) | (0xC0);
		OPTION->VREFTCR |= 1 << 5;

		OPTION->LDO1P2TC = (OPTION->LDO1P2TC & (0x3F)) | (0x40);
		OPTION->LDO1P2TC = (OPTION->LDO1P2TC & (0x3F)) | (0x80);
		OPTION->LDO1P2TC = (OPTION->LDO1P2TC & (0x3F)) | (0xC0);
		OPTION->LDO1P2TC |= 1 << 6;

		// LTPrintf("vreftcr:%x \r\n", OPTION->VREFTCR);
		// LTPrintf("LDO1P2TC:%x \r\n", OPTION->LDO1P2TC);
#endif

#if close_IO
		eport_init_config.pin = EPORT_PIN_0;
		eport_init_config.mode = EPORT_OUTPUT;
		eport_init_config.pullup = EPORT_Pull_up;
		eport_init_config.int_enable = Disable;
		EPORT_Init(EPORT0, &eport_init_config);
		EPORT_WritePin(EPORT0, EPORT_PIN_0, Set);

		eport_init_config.pin = EPORT_PIN_1;
		EPORT_Init(EPORT0, &eport_init_config);
		EPORT_WritePin(EPORT0, EPORT_PIN_1, Set);

		eport_init_config.pin = EPORT_PIN_2;
		EPORT_Init(EPORT0, &eport_init_config);
		EPORT_WritePin(EPORT0, EPORT_PIN_2, Set);

		eport_init_config.pin = EPORT_PIN_3;
		EPORT_Init(EPORT0, &eport_init_config);
		EPORT_WritePin(EPORT0, EPORT_PIN_3, Set);

		// /* 切换EPORT1_0,EPORT1_6 */
		PIN_EPORT1_0();
		PIN_EPORT1_6();

		/* EBI 切换 EPORT1_1,EPORT1_2,EPORT1_4,EPORT1_5 */
		PIN_EPORT1_1245();

		eport_init_config.pin = EPORT_PIN_0;
		EPORT_Init(EPORT1, &eport_init_config);
		EPORT_WritePin(EPORT1, EPORT_PIN_0, Set);

		eport_init_config.pin = EPORT_PIN_1;
		EPORT_Init(EPORT1, &eport_init_config);
		EPORT_WritePin(EPORT1, EPORT_PIN_1, Set);

		eport_init_config.pin = EPORT_PIN_2;
		EPORT_Init(EPORT1, &eport_init_config);
		EPORT_WritePin(EPORT1, EPORT_PIN_2, Set);

		eport_init_config.pin = EPORT_PIN_3;
		EPORT_Init(EPORT1, &eport_init_config);
		EPORT_WritePin(EPORT1, EPORT_PIN_3, Set);

		eport_init_config.pin = EPORT_PIN_4;
		EPORT_Init(EPORT1, &eport_init_config);
		EPORT_WritePin(EPORT1, EPORT_PIN_4, Set);

		eport_init_config.pin = EPORT_PIN_5;
		EPORT_Init(EPORT1, &eport_init_config);
		EPORT_WritePin(EPORT1, EPORT_PIN_5, Set);

		eport_init_config.pin = EPORT_PIN_6;
		EPORT_Init(EPORT1, &eport_init_config);
		EPORT_WritePin(EPORT1, EPORT_PIN_6, Set);

		eport_init_config.pin = EPORT_PIN_7;
		EPORT_Init(EPORT1, &eport_init_config);
		EPORT_WritePin(EPORT1, EPORT_PIN_7, Set);

		/* 切换EPORT2*/
		PIN_EPORT2_0();
		PIN_EPORT2_1();
		PIN_EPORT2_2();
		PIN_EPORT2_3();
		PIN_EPORT2_4();
		PIN_EPORT2_5();
		PIN_EPORT2_6();
		PIN_EPORT2_7();

		eport_init_config.pin = EPORT_PIN_0;
		eport_init_config.mode = EPORT_OUTPUT;
		EPORT_Init(EPORT2, &eport_init_config);
		EPORT_WritePin(EPORT2, EPORT_PIN_0, Set);

		eport_init_config.pin = EPORT_PIN_1;
		eport_init_config.mode = EPORT_OUTPUT;
		EPORT_Init(EPORT2, &eport_init_config);
		EPORT_WritePin(EPORT2, EPORT_PIN_1, Set);

		eport_init_config.pin = EPORT_PIN_2;
		eport_init_config.mode = EPORT_OUTPUT;
		EPORT_Init(EPORT2, &eport_init_config);
		EPORT_WritePin(EPORT2, EPORT_PIN_2, Set);

		eport_init_config.pin = EPORT_PIN_3;
		eport_init_config.mode = EPORT_OUTPUT;
		EPORT_Init(EPORT2, &eport_init_config);
		EPORT_WritePin(EPORT2, EPORT_PIN_3, Set);

		eport_init_config.pin = EPORT_PIN_4;
		eport_init_config.mode = EPORT_OUTPUT;
		EPORT_Init(EPORT2, &eport_init_config);
		EPORT_WritePin(EPORT2, EPORT_PIN_4, Set);

		eport_init_config.pin = EPORT_PIN_5;
		eport_init_config.mode = EPORT_OUTPUT;
		EPORT_Init(EPORT2, &eport_init_config);
		EPORT_WritePin(EPORT2, EPORT_PIN_5, Set);

		eport_init_config.pin = EPORT_PIN_6;
		eport_init_config.mode = EPORT_OUTPUT;
		EPORT_Init(EPORT2, &eport_init_config);
		EPORT_WritePin(EPORT2, EPORT_PIN_6, Set);

		eport_init_config.pin = EPORT_PIN_7;
		eport_init_config.mode = EPORT_OUTPUT;
		EPORT_Init(EPORT2, &eport_init_config);
		EPORT_WritePin(EPORT2, EPORT_PIN_7, Set);

		/* PWM PIN 脚 */
		CCM->CPPDC = 0x0FF00000; /*Enable pull down */

		PWM0->PCR = 0;
		PWM0->PPCR = 0xF0000; /* PWM关闭 PIN脚设置输出，输出低电平 */

		PWM1->PCR = 0;
		PWM1->PPCR = 0xF0000; /* PWM关闭 PIN脚设置输出，输出低电平 */

		/* EBI脚 */
		MDPI->IOCR |= 3 << 2;		/* D[15:0] as GPIO */
		MDPI->GPIODIR = 0xFFFF0000; /* set output */
		MDPI->GPIODO = 0xFFFF0000;	/* output High*/

		/* I2C 脚 */
		I2C->I2CPCR = 0xC3; /*GPIO pull up ,CMOS */
		I2C->I2CDDR = 0x03; /* output */
		I2C->I2CPDR = 0x03; /* output high */
#endif

#if 1
	/*
	 * 注意如果不需要中断服务函数就不要开启全局中断，休眠一样能唤醒。
	 *
	 * 需要中断服务函数则，必须将中断向量表更新到sram中，以确保休眠唤醒后
	 * 中断服务函数的地址和中断向量表的数据是可以被访问的。
	 * 假如关闭了XIP，在唤醒后又是先进的中断，中断服务程序的地址入口又是XIP映射的，就会导致程序无法访问。
	 *  */
	//			memcpy((uint8_t*)(0x810000),data,sizeof(data));
	//
	//			/* 更改C0内核的vbr寄存器,中断向量基地址 */
	//			asm("lrw r1,0x810000");
	//		  	asm("mtcr r1,vbr");
	//
	//			/* 把当前的vbr 数值复制到sram地址，打印出来看看 */
	//			asm("mfcr r1,vbr");
	//		    asm("lrw r5, 0x00810200");
	//		    asm("stw r1,(r5)");
	//		    LTPrintf("%x\r\n",*(uint32_t *)0x810200);

	/* 使用把休眠函数搬运到sram里跑，不开中断 */
	// memcpy((uint8_t*)(0x800100),Sleep_in_Ram,sizeof(Sleep_in_Ram));

	CACHE->LMEM_ACRG = 0;
	CACHE->LMEM_CCR &= ~0x01; /* 关闭Cache */

	DelayMS(10);

	// /* 使用ROM 里的sleep 函数 */
	asm("jsri 0x100");

	/* 使用ram 里的sleep 函数 */
	// asm("jsri 0x800100");

	DelayMS(10);

	// asm("stop");

	//			/* 更改C0内核的vbr寄存器,中断向量基地址，改回QSPI0的中断向量基地址 */
	//			asm("lrw r1,0x60000000");
	//		  	asm("mtcr r1,vbr");
	//
	//			/* 把当前的vbr 数值复制到sram地址，打印出来看看 */
	//		  	asm("mfcr r1,vbr");
	//		    asm("lrw r5, 0x00810200");
	//		    asm("stw r1,(r5)");
	//		    LTPrintf("%x\r\n",*(uint32_t *)0x810200);


//--唤醒源触发后-------------------------------------------------------------------------
#if close_IO

		/* 切换EPORT1_0,EPORT1_6 */
		PIN_CLKOUT_Default();
		PIN_RSTOUT_Default();

		/* 恢复所有串口脚*/
		PIN_CANRX_Default();
		PIN_CANTX_Default();
		PIN_RXD0_Default();
		PIN_TXD0_Default();
		PIN_RXD1_Default();
		PIN_TXD1_Default();
		PIN_TXD2_Default();
		PIN_RXD2_Default();
		DelayMS(3);

#endif

		/* 开启其他的sram*/
#if close_other_ram

		CCM->MCU_RAM_PRIOCR &= 0x0000FFFF;
		// LTPrintf("CCM->MCU_RAM_PRIOCR:%x\r\n",CCM->MCU_RAM_PRIOCR);
#endif

		/* 打开cache */
		Cache_Init();

#if close_rtc
		/* 打开RTC */
		for (; Bit_Read(RTC->PRENR, 0x400) == 0;) /* wait RTC_EN_Update_EN to 1 */
			asm("nop");
		RTC->PRENR |= 0x01;						  /* enable RTC */
		for (; Bit_Read(RTC->PRENR, 0x400) == 0;) /* wait RTC_EN_Update_EN to 1 */
			asm("nop");
#endif

#if close_1P2

		OPTION->VREFTCR = (OPTION->VREFTCR & (0x3F)) | (0x40);
		OPTION->VREFTCR = (OPTION->VREFTCR & (0x3F)) | (0x80);
		OPTION->VREFTCR = (OPTION->VREFTCR & (0x3F)) | (0xC0);
		OPTION->VREFTCR &= ~(1 << 5); // 上电
		OPTION->VREFTCR &= (0x3F);
		// LTPrintf("vreftcr:%x \r\n", OPTION->VREFTCR);

		OPTION->LDO1P2TC = (OPTION->LDO1P2TC & (0x3F)) | (0x40);
		OPTION->LDO1P2TC = (OPTION->LDO1P2TC & (0x3F)) | (0x80);
		OPTION->LDO1P2TC = (OPTION->LDO1P2TC & (0x3F)) | (0xC0);
		OPTION->LDO1P2TC &= ~(1 << 6); // 上电
		OPTION->LDO1P2TC &= (0x3F);
		// LTPrintf("LDO1P2TC:%x \r\n", OPTION->LDO1P2TC);
#endif

		// disable eport0 interrupt
		EPORT0->EPIER = 0;

		//开启屏背光，TFT退出休眠
		TFT_Exit_Sleep();
		LCD_BL_Init(gDutyBuf[var[VAR_BL * 2 + 1]]);

#else
		/*QSPI0 XIP 直接进入休眠 */
		*(uint32_t *)(0x810000) = 0x12765438;
		//LTPrintf("%x \r\n", *(uint32_t *)(0x810000));

		*(uint32_t *)(0x820000) = 0x13765438;
		//LTPrintf("%x \r\n", *(uint32_t *)(0x820000));

		*(uint32_t *)(0x830000) = 0x14765438;
		//LTPrintf("%x \r\n", *(uint32_t *)(0x830000));

		*(uint32_t *)(0x840000) = 0x15765438;
		//LTPrintf("%x \r\n", *(uint32_t *)(0x840000));

		CCM->MCURAMPRIOCR = (CCM->MCURAMPRIOCR & 0x3FFFFFFF) | (1 << 30);
		CCM->MCURAMPRIOCR = (CCM->MCURAMPRIOCR & 0x3FFFFFFF) | (2 << 30);
		CCM->MCURAMPRIOCR = (CCM->MCURAMPRIOCR & 0x3FFFFFFF) | (3 << 30);

		CCM->MCURAMPRIOCR |= (0x1F) << 17;
		CCM->MCURAMPRIOCR |= (0x1F) << 25;

		DelayMS(100);

		Bit_Set(CLOCK->SYNCR, CLOCK_SYNCR_SLEEP_MASK);

		DelayMS(500);
		CCM->MCURAMPRIOCR = 0x03;

		// LTPrintf("0x810000:%x \r\n", *(uint32_t *)(0x810000));
		// LTPrintf("0x820000:%x \r\n", *(uint32_t *)(0x820000));
		// LTPrintf("0x830000:%x \r\n", *(uint32_t *)(0x830000));
		// LTPrintf("0x840000:%x \r\n", *(uint32_t *)(0x840000));

		/************************/
#endif
	}
	else
	{
		// LTPrintf("Can't in Low Power\r\n");
	}
}

void WDT_Init(void)
{
	WDT->WCR &= ~0x01;
	WDT->WCR |= 0x70;
	WDT->WCR |= 0x08;
	WDT->WMR  = 32000;					 //看门狗的复位值设1S (128K/16) 8000:1S 16000:2S 24000:3S  32000:4S
	WDT->WCR |= 0x02;					 //
	WDT->WCR |= 0x01;
}

void WDT_FeedDog(void)
{
	 WDT->WSR = 0x5555;
	 WDT->WSR = 0xAAAA;
}
